Step-by step introduction to I2C EEPROM

Dependencies:   mbed

Revision:
2:41fccbb2e863
Parent:
1:c1f476b94bb3
Child:
3:58bd0878bb0f
--- a/main.cpp	Tue Jan 12 09:13:00 2016 +0000
+++ b/main.cpp	Tue Jan 12 22:18:21 2016 +0000
@@ -14,8 +14,22 @@
 
 int main()
 {
-    pc.printf("Read data from EEPROM sequentially");
+    pc.printf("Read data from EEPROM sequentially\r\n");
     char data[1];
+    char data_write[3]; //Array for address and data
+    // Type in address
+    data_write[0] = 0;
+    data_write[1] = 0;
+    // Type data
+    data_write[2] = 1;
+    i2c.write(EEPROM_ADDR, data_write, 3);
+    wait_ms(6); // Wait eeprom internal write cycle (5ms) + 1ms
+    // Reset eeprom pointer address
+    char eeprom_address[2] = {0, 0};
+    i2c.write(EEPROM_ADDR, eeprom_address, 2, true);
+    i2c.read(EEPROM_ADDR, data, 1, false);
+    pc.printf("Written data: %d\n\r",data[0]);
+
     while (1) {
         if (mybutton == 0) { // Button is pressed
             i2c.read(EEPROM_ADDR, data, 1);