Skip to content

Commit

Permalink
Fix AD5421 driver bugs
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Brandon-Hurst authored and buha committed Dec 9, 2024
1 parent 19084c7 commit cc73a3d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/dac/ad5421/ad5421.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ int32_t ad5421_set(struct ad5421_dev *dev,
status = no_os_spi_write_and_read(dev->spi_desc,
tx_buffer,
3);
if (status != 3) {
if (status != 0) {
return -1;
} else {
return 0;
Expand All @@ -393,13 +393,13 @@ int32_t ad5421_set(struct ad5421_dev *dev,
int32_t ad5421_get(struct ad5421_dev *dev)
{
int32_t return_val = 0;
uint8_t rx_buffer[3] = {0, 0, 0};
uint8_t rx_buffer[3] = {AD5421_NO_OP, 0, 0};
int8_t status = 0;

status = no_os_spi_write_and_read(dev->spi_desc,
rx_buffer,
3);
if (status != 3) {
if (status != 0) {
return -1;
}
return_val |= (int32_t)(rx_buffer[1] << 8);
Expand Down
1 change: 1 addition & 0 deletions drivers/dac/ad5421/ad5421.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#define AD5421_CMDWRGAIN 4
#define AD5421_CMDRST 7
#define AD5421_CMDMEASVTEMP 8
#define AD5421_NO_OP 9
#define AD5421_CMDRDDAC 129
#define AD5421_CMDRDCTRL 130
#define AD5421_CMDRDOFFSET 131
Expand Down

0 comments on commit cc73a3d

Please sign in to comment.