Mbed read and write data to EEPROM( I2C interface)

Mbed read and write data to EEPROM( I2C interface). Use LPC 1114 MPU and EEPROM 24LC512. In my circuit connection , EEPROM’s address is 0x50. Pullup resistor is required with sda and scl lines.

 LPC 1114 MPU and EEPROM 24LC512

Code

#include “mbed.h”
#define eep_add ((uint8_t) 0x50<<1)

I2C i2c(dp5, dp27);
Serial pc(dp16, dp15);
 

char *data;
char buf[40]=”hello ,welcome to ngolongtech.net”;
int main() {
    i2c.frequency(100000);
    while(1){
        char cmd[sizeof(buf)+2];
        cmd[0]=0x00>>8;
        cmd[1]=0x00&0xFF;
        for (int i=0;i<sizeof(buf);i++){
            cmd[2+i]=buf[i];
        }
        i2c.write(eep_add,cmd,2+sizeof(buf));//write
        wait(0.1);
        cmd[0]=0x00>>8;
        cmd[1]=0x00&0xFF;
        i2c.write(eep_add,cmd,2);
        i2c.read(eep_add,data,sizeof(buf));//read
        pc.printf(“%sn”,data);
        wait(0.01);
    }
}


Tags:

Most views

Leave a Reply

Your email address will not be published. Required fields are marked *