This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

why i am i not able to write anything on 24LC356 eeprom

I am using blenano with mbed compiler and a 24LC256 eeprom.

the output o screen I get is the no. of total chars, i.e, 65355. below is the code.

#include "mbed.h"
#include "ble/BLE.h"
#include "SoftI2C.h"

int test =1000;

  lcd.clear();
                lcd.setPosition(0, 0);
    lcd.printf("Writing bytes 0-16\n");
  wait(0.2);
    char data[4];
   
 
    data[0] = 0;       // MSB address
    data[1] = 255;     // LSB address
    data[2] = test;     // data
    data[3] = test>>8;
    if(i2c.write(0xA0, data, 4)) {
        lcd.clear();
                lcd.setPosition(0, 0);

        lcd.printf("Write failed\n");
    }
    while(i2c.write(0xA0, NULL, 0));           
 lcd.clear();
                lcd.setPosition(0, 0);
    lcd.printf("Setting read pointer to 0\n");
 wait(0.2);
   
 lcd.clear();
 lcd.setPosition(0, 0);
  lcd.printf("Reading back data bytes 0-16\n");
   wait(0.2);
    char response[2];
    for(int i=0; i<256; i++) {
        if(i2c.read(0xA0+0x01, response, 2)) {
            error("Read failed\n");
        }
       lcd.clear();
  lcd.setPosition(0, 0);
 lcd.printf("address  %d", (response[0]<<8)|response[1]);
Parents
  • */

    #include "mbed.h"
    #include "wire.h"
     
    #define BLE_Nano
    //#define nRF_51822
     
     
    #ifdef nRF_51822
    #define SCL         28
    #define SDA         29
    #endif
     
    #ifdef BLE_Nano
    #define SCL         7  
    #define SDA         6
    #endif
     
    #define DEV_ADDR    0xA0
     
    Serial pc(USBTX, USBRX);
    TwoWire Wire = TwoWire(NRF_TWI0);
     
    void AT24C512_WriteBytes(uint16_t addr, uint8_t *pbuf, uint16_t length)
    {
        Wire.beginTransmission(DEV_ADDR);
        Wire.write( (uint8_t)addr>>8 );
        Wire.write( (uint8_t)addr );
        Wire.write(pbuf, length);
        Wire.endTransmission();
    }
     
    void AT24C512_ReadBytes(uint16_t addr, uint8_t *pbuf, uint16_t length)
    {
        Wire.beginTransmission(DEV_ADDR);
        Wire.write( (uint8_t)addr>>8 );
        Wire.write( (uint8_t)addr );    
        Wire.endTransmission();
           
        Wire.requestFrom(DEV_ADDR+1, length);
        while( Wire.available() > 0 )
        {
            *pbuf = Wire.read();
            pbuf++;
        }
    }
     
     
    static uint8_t wt_data[10] = {'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd'};
    static uint8_t rd_data[10];
     
    static uint16_t index;
     
    int main(void)
    {
        pc.baud(9600);
        wait(5);
        //Wire.begin();
        Wire.begin(SCL, SDA, TWI_FREQUENCY_100K);
        pc.printf("IIC Demo Start \r\n");
        
        AT24C512_WriteBytes(0, wt_data, 10);
        wait(0.1);
        
        while(1)
        {
            AT24C512_ReadBytes(0, rd_data, 10);     
            pc.printf("Read data from AT24C512 \r\n");
            for(index=0; index<10; index++)
            {
                pc.putc(rd_data[index]);
                rd_data[index] = 0x00;
            }
            pc.printf("\r\n");
            wait(1);
        }
    }
    
Reply
  • */

    #include "mbed.h"
    #include "wire.h"
     
    #define BLE_Nano
    //#define nRF_51822
     
     
    #ifdef nRF_51822
    #define SCL         28
    #define SDA         29
    #endif
     
    #ifdef BLE_Nano
    #define SCL         7  
    #define SDA         6
    #endif
     
    #define DEV_ADDR    0xA0
     
    Serial pc(USBTX, USBRX);
    TwoWire Wire = TwoWire(NRF_TWI0);
     
    void AT24C512_WriteBytes(uint16_t addr, uint8_t *pbuf, uint16_t length)
    {
        Wire.beginTransmission(DEV_ADDR);
        Wire.write( (uint8_t)addr>>8 );
        Wire.write( (uint8_t)addr );
        Wire.write(pbuf, length);
        Wire.endTransmission();
    }
     
    void AT24C512_ReadBytes(uint16_t addr, uint8_t *pbuf, uint16_t length)
    {
        Wire.beginTransmission(DEV_ADDR);
        Wire.write( (uint8_t)addr>>8 );
        Wire.write( (uint8_t)addr );    
        Wire.endTransmission();
           
        Wire.requestFrom(DEV_ADDR+1, length);
        while( Wire.available() > 0 )
        {
            *pbuf = Wire.read();
            pbuf++;
        }
    }
     
     
    static uint8_t wt_data[10] = {'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd'};
    static uint8_t rd_data[10];
     
    static uint16_t index;
     
    int main(void)
    {
        pc.baud(9600);
        wait(5);
        //Wire.begin();
        Wire.begin(SCL, SDA, TWI_FREQUENCY_100K);
        pc.printf("IIC Demo Start \r\n");
        
        AT24C512_WriteBytes(0, wt_data, 10);
        wait(0.1);
        
        while(1)
        {
            AT24C512_ReadBytes(0, rd_data, 10);     
            pc.printf("Read data from AT24C512 \r\n");
            for(index=0; index<10; index++)
            {
                pc.putc(rd_data[index]);
                rd_data[index] = 0x00;
            }
            pc.printf("\r\n");
            wait(1);
        }
    }
    
Children
No Data
Related