mFS file system library for EEPROM memory chips.

Revision:
5:a0fe74dce80d
Parent:
0:cbf45dde2b49
Child:
7:5ac5121bb4e0
--- a/i2c_eeprom.cpp	Mon Feb 21 09:53:32 2011 +0000
+++ b/i2c_eeprom.cpp	Mon Feb 21 18:26:27 2011 +0000
@@ -1,32 +1,28 @@
-/*H****************************************************************************
+/** @file i2c_eeprom.cpp */
+/*CPP**************************************************************************
 * FILENAME :        i2c_eeprom.cpp                                            *
 *                                                                             *
 * DESCRIPTION :                                                               *
 *       Simple library for external I2C EEEPROM.                              *
 *                                                                             *
 * AUTHOR :    Olli Vanhoja        START DATE :    2011-02-17                  *
-*******************************************************************************
-*
-* CHANGES :
-*
-* VERSION DATE       WHO             DETAIL
-* 0.1     2011-02-21 Olli Vanhoja    Initial release version
-*
-*H*/
+******************************************************************************/
 
 #include "mbed.h"
 #include "i2c_eeprom.h"
 
 I2C i2c(p28, p27);
 DigitalOut BusyLed(LED1);
+DigitalInOut scl_ext(p20); /** \attention Clock override pin connected to SCL */
 
-i2c_eeprom::i2c_eeprom()
-{
-}
-
-i2c_eeprom::i2c_eeprom(int hwAddr)
+i2c_eeprom::i2c_eeprom(int hwAddr, int speed)
 {
     i_i2c_address = hwAddr;
+    
+    scl_ext.input();      // Make it input to start with...
+    scl_ext.mode(PullUp); // ...with pull up
+        
+    i2c.frequency(speed);
 }
 
 void i2c_eeprom::write(char *data, uint16 iAddr, unsigned int n)
@@ -86,11 +82,27 @@
     i2c_data[1] = *pi2c_data[1];
     
     // Send read command
+    srread:
     if(i2c.write(i_i2c_address, i2c_data, 2))
-        error("Read failed! ref:1\n\r");
+    {
+        i2c.start();
+        scl_ext = 0;          // Setup override pin to pull clock low
+        scl_ext.input();      // Make it input to start with...
+        scl_ext.mode(PullUp); // ...with pull up
+        wait(0.00005);        // Pause after stop
+        scl_ext.output();     // Override clock pin low
+        wait(0.00005);        // Pause
+        scl_ext.input();      // Remove override...
+        scl_ext.mode(PullUp); // ...with pull up
+        wait(0.00005);        // Pause again
+
+        i2c.start();
+        i2c.stop();
+        goto srread;
+    }
     
     if(i2c.read(i_i2c_address, out, n))
-        error("Read failed! ref:2\n\r");
+        error("Read failed!\n\r");
     
     BusyLed = 0;
 }