Interface to Analog devices AD5258 digital I2C potentiometer

Revision:
1:64570234d7b5
Parent:
0:8920c7d857d8
Child:
2:8a71db02417b
--- 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