Interface to Analog devices AD5258 digital I2C potentiometer
Revision 1:64570234d7b5, committed 2013-11-11
- Comitter:
- RodColeman
- Date:
- Mon Nov 11 13:08:08 2013 +0000
- Parent:
- 0:8920c7d857d8
- Child:
- 2:8a71db02417b
- Commit message:
- Add EEPROM access modes, and store/restore
Changed in this revision
AD5258.cpp | Show annotated file Show diff for this revision Revisions of this file |
AD5258.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/AD5258.cpp Mon Nov 11 11:00:35 2013 +0000 +++ b/AD5258.cpp Mon Nov 11 13:08:08 2013 +0000 @@ -6,8 +6,13 @@ _address = address; } + + // RDAC ACCESS: values of 0 to 0x3F for full pot range. + int AD5258::read() { char foo[1]; + foo[0] = 00; // command to read RDAC + _i2c.write(_address, foo, 1); _i2c.read(_address, foo, 1); return foo[0]; } @@ -18,4 +23,35 @@ foo[1] = data; _i2c.write(_address, foo, 2); } - \ No newline at end of file + +// EEPROM ACCESS + +int AD5258::readEE() { + char foo[1]; + foo[0] = 0x20; // command to read RDAC + _i2c.write(_address, foo, 1); + _i2c.read(_address, foo, 1); + return foo[0]; +} + +void AD5258::writeEE(int data) { + char foo[2]; + foo[0] = 0x20; + foo[1] = data; + _i2c.write(_address, foo, 2); +} + + // Store RDAC value to EEPROM, for nonvol retention: + void AD5258::store(void) { + char foo[1]; + foo[0] = 0xC0; // command to store RDAC to EE + _i2c.write(_address, foo, 1); + } + + // restore RDAC value from EEPROM + void AD5258::restore(void) { + char foo[2]; + foo[0] = 0xA0; // command to store RDAC to EE + foo[1] = 0x80; // NOP to restore low power mode + _i2c.write(_address, foo, 1); + } \ No newline at end of file
--- a/AD5258.h Mon Nov 11 11:00:35 2013 +0000 +++ b/AD5258.h Mon Nov 11 13:08:08 2013 +0000 @@ -21,11 +21,41 @@ */ int read(); - /** Write to the IO pins + /** Write to the RDAC * * @param data The 6-bits value: 0x00 to 0x3F to write to the pots RDAC */ void write(int data); + + // READ and WRITE EEPROM + + /** Read the EEPROM value + * + * @return The 6-bit value read + */ + int readEE(); + + /** Write to the RDAC + * + * @param data The 6-bits value: 0x00 to 0x3F to write to the pots RDAC + */ + void writeEE(int data); + + + + + // STORE and RESTORE: + + /** store the RDAC value into the EEPROM, for nonvolatile keeping of the value + * + */ + void store(void); + + /** restore to the RDAC the value from the EEPROM. NOP issued afterward, to put back into low-power idle mode + * + */ + void restore(void); + private: I2C _i2c;