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
  • Did you solve your initial problem? I have not tested this, but you should be able to write and read 32-bit words similar to this:

    void write32(uint16_t addr, uint32_t value)
    {
    	uint8_t pbuf[4] = {value >> 24, value >> 16, value >> 8, value};
    	AT24C512_WriteBytes(addr, pbuf, sizeof(pbuf));
    }
    
    uint32_t read32(uint16_t addr)
    {
    	uint32_t result;
    	uint8_t pbuf[4];
    	AT24C512_ReadBytes(addr, pbuf, sizeof(pbuf));
    	result = (pbuf[0] << 24) | (pbuf[1] << 16) | (pbuf[2] << 8) | (pbuf[3]);
    	return result;
    }
    
Reply
  • Did you solve your initial problem? I have not tested this, but you should be able to write and read 32-bit words similar to this:

    void write32(uint16_t addr, uint32_t value)
    {
    	uint8_t pbuf[4] = {value >> 24, value >> 16, value >> 8, value};
    	AT24C512_WriteBytes(addr, pbuf, sizeof(pbuf));
    }
    
    uint32_t read32(uint16_t addr)
    {
    	uint32_t result;
    	uint8_t pbuf[4];
    	AT24C512_ReadBytes(addr, pbuf, sizeof(pbuf));
    	result = (pbuf[0] << 24) | (pbuf[1] << 16) | (pbuf[2] << 8) | (pbuf[3]);
    	return result;
    }
    
Children
No Data
Related