Skip to content

Commit cc73a3d

Browse files
Brandon-Hurstbuha
authored andcommitted
Fix AD5421 driver bugs
AD5421 driver had a bug when integrating into a custom example: - SPI R/W status checks check against an expected length, rather than 0/-1 which is what the No-OS API comments indicate it should return. - Very minor: I added the "No-Op" code from AD5421 datasheet (0x09). Currently the driver sends 0x00 which should suffice for reading data back, but I added 0x09 to match what the AD5421 GUI sends. Signed-off-by: Brandon Hurst <[email protected]>
1 parent 19084c7 commit cc73a3d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

drivers/dac/ad5421/ad5421.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ int32_t ad5421_set(struct ad5421_dev *dev,
376376
status = no_os_spi_write_and_read(dev->spi_desc,
377377
tx_buffer,
378378
3);
379-
if (status != 3) {
379+
if (status != 0) {
380380
return -1;
381381
} else {
382382
return 0;
@@ -393,13 +393,13 @@ int32_t ad5421_set(struct ad5421_dev *dev,
393393
int32_t ad5421_get(struct ad5421_dev *dev)
394394
{
395395
int32_t return_val = 0;
396-
uint8_t rx_buffer[3] = {0, 0, 0};
396+
uint8_t rx_buffer[3] = {AD5421_NO_OP, 0, 0};
397397
int8_t status = 0;
398398

399399
status = no_os_spi_write_and_read(dev->spi_desc,
400400
rx_buffer,
401401
3);
402-
if (status != 3) {
402+
if (status != 0) {
403403
return -1;
404404
}
405405
return_val |= (int32_t)(rx_buffer[1] << 8);

drivers/dac/ad5421/ad5421.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#define AD5421_CMDWRGAIN 4
5252
#define AD5421_CMDRST 7
5353
#define AD5421_CMDMEASVTEMP 8
54+
#define AD5421_NO_OP 9
5455
#define AD5421_CMDRDDAC 129
5556
#define AD5421_CMDRDCTRL 130
5657
#define AD5421_CMDRDOFFSET 131

0 commit comments

Comments
 (0)