Driver for the AD5270 digipot
Dependents: ad5270-helloworld CN0357 CN0396
For additional information check out the mbed page of the Analog Devices wiki: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
Revision 1:9f9dd8c48e8a, committed 2016-08-18
- Comitter:
- adisuciu
- Date:
- Thu Aug 18 12:38:39 2016 +0000
- Parent:
- 0:18d434f6f122
- Commit message:
- Implemented basic daisychain support
Changed in this revision
AD5270.cpp | Show annotated file Show diff for this revision Revisions of this file |
AD5270.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 18d434f6f122 -r 9f9dd8c48e8a AD5270.cpp --- a/AD5270.cpp Tue May 03 12:55:30 2016 +0000 +++ b/AD5270.cpp Thu Aug 18 12:38:39 2016 +0000 @@ -125,11 +125,11 @@ * @param data - (optional)value for the requested command * @return response form the AD5270 */ -uint16_t AD5270::write_cmd(uint8_t command, uint16_t data) +uint16_t AD5270::write_cmd(uint8_t command, uint16_t data, bool toggle_cs) { /* build 16 bit data to be written - Command + Value */ uint16_t ui16Command = ((command & 0x3C) << 8) | (data & 0x3FF); - return write_reg(ui16Command); + return write_reg(ui16Command, toggle_cs); } /** @@ -164,16 +164,16 @@ * @param data to be written * @return data returned by the AD5270 */ -uint16_t AD5270::write_reg(uint16_t data) +uint16_t AD5270::write_reg(uint16_t data, bool toggle_cs) { uint16_t result; uint8_t upper_byte = (data >> 8) & 0xFF; uint8_t lower_byte = data & 0xFF; ad5270.format(8, _SPI_MODE); - cs = false; + cs = false & toggle_cs; result = ((ad5270.write(upper_byte)) << 8); result |= ad5270.write(lower_byte); - cs = true; + cs = true & toggle_cs; return result; } @@ -279,5 +279,11 @@ write_cmd(SW_SHUTDOWN, static_cast<uint8_t>(mode)); } +void AD5270::daisy_chain(uint8_t *buffer, uint8_t size) +{ + cs = 0; + for(int i = 0; i < size; i++) + buffer[i] = ad5270.write(buffer[i]); + cs = 1; +} -
diff -r 18d434f6f122 -r 9f9dd8c48e8a AD5270.h --- a/AD5270.h Tue May 03 12:55:30 2016 +0000 +++ b/AD5270.h Thu Aug 18 12:38:39 2016 +0000 @@ -104,8 +104,8 @@ /* Low level methods */ - uint16_t write_cmd(uint8_t command, uint16_t data = 0x00); - uint16_t write_reg(uint16_t data); + uint16_t write_cmd(uint8_t command, uint16_t data = 0x00, bool toggle_cs = true); + uint16_t write_reg(uint16_t data, bool toggle_cs = true); /* Methods that deal with resistance in float format*/ uint16_t calc_RDAC(float resistance); @@ -120,6 +120,8 @@ uint8_t read_50TP_last_address(void); uint16_t read_50TP_memory(uint8_t address); + void daisy_chain(uint8_t *buffer, uint8_t size); + SPI ad5270; ///< SPI instance of the AD5270 DigitalOut cs; ///< DigitalOut instance for the chip select of the AD5270