I2C EEProm library

Fork of eeprom by FRA221_2015

Files at this revision

API Documentation at this revision

Comitter:
soulx
Date:
Mon Oct 26 16:43:07 2015 +0000
Parent:
1:e91aa7bef1f9
Child:
3:df82ebf4be54
Commit message:
edit ack chacking with wait_ms(5) *Application Note:AN1028

Changed in this revision

eeprom.cpp Show annotated file Show diff for this revision Revisions of this file
eeprom.h Show annotated file Show diff for this revision Revisions of this file
--- a/eeprom.cpp	Tue Aug 25 11:59:20 2015 +0000
+++ b/eeprom.cpp	Mon Oct 26 16:43:07 2015 +0000
@@ -3,6 +3,7 @@
 Date: 27 december 2011
 Version: 1.0
 ************************************************************/
+#include "mbed.h"
 #include "eeprom.h"
 
 #define BIT_SET(x,n) (x=x | (0x01<<n))
@@ -50,10 +51,14 @@
                     break;
                   case T24C32 :
                   case T24C64 :
+                  
                     if(address > 7) {
                       _errnum = EEPROM_BadAddress;
                     }
+                    
                     _address = _address << 1;
+                    
+                    
                     _page_write = 32;
                     _page_number = 1;
                     break;
@@ -98,7 +103,7 @@
     _size = T24C1024;
   
   // Set I2C frequency
-  _i2c.frequency(400000);
+  _i2c.frequency(100000);
 }
 
 void EEPROM::write(uint16_t address, int8_t data)
@@ -149,7 +154,7 @@
     cmd[2] = (uint8_t) data;
   }
   
-  //printf("len %d address %02x cmd[0] %02x cmd[1] %02x cmd[2] %02x\n",len,addr,cmd[0],cmd[1],cmd[2]);
+ // printf("len %d address %02x cmd[0] %02x cmd[1] %02x cmd[2] %02x\n",len,addr,cmd[0],cmd[1],cmd[2]);
  
   ack = _i2c.write((int)addr,(char *)cmd,len);
   if(ack != 0) {
@@ -448,7 +453,7 @@
   memcpy(cmd,&data,4);
   
   write(address,cmd,4);
-  
+
 }
 
 void EEPROM::write(uint16_t address, float data)
@@ -744,12 +749,13 @@
   addr = EEPROM_Address | _address;
   
   cmd = 0;
-  
+  /*
   // Wait end of write
   do {
        ack = _i2c.write((int)addr,(char *)cmd,0);
   } while(ack != 0);
-
+*/
+    wait_ms(5);
 }
 
 uint32_t EEPROM::getSize(void)
--- a/eeprom.h	Tue Aug 25 11:59:20 2015 +0000
+++ b/eeprom.h	Mon Oct 26 16:43:07 2015 +0000
@@ -46,7 +46,7 @@
      * @param type : eeprom type (TypeEeprom) 
      * @return none
     */
-    EEPROM(PinName sda, PinName scl, uint8_t address, TypeEeprom type=T24C16);
+    EEPROM(PinName sda, PinName scl, uint8_t address, TypeEeprom type=T24C64);
     
     /*
      * Random read byte