mi14chal
Newbie level 5
- Joined
- Oct 30, 2010
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,354
I'm having a problem with AT24C256, because I cannot save my data there. I wrote simple code to read and to write some data to AT24C256:
But when I'm using this code for writing not work correctly, b/c when I try to save some data, and then try to read it I always get a value 0xFF. And my question is where is a problem? I only want to add I connected pin WP to gnd, and I don't know what could be a problem. And I2C frequency is 100kHz.
Code:
void eepromWriteByte(unsigned char addr, unsigned int eepromAddr, unsigned char byte)
{
i2c0Start();
i2c0SetAddress(addr);
i2c0Send(eepromAddr >> 8); // MSB
i2c0Send(eepromAddr & 0xFF); // LSB
i2c0Send(byte);
i2c0Stop();
delay_ms(20);
}
unsigned char eepromReadByte(unsigned char addr, unsigned int eepromAddr)
{
i2c0Start();
i2c0SetAddress(addr);
i2c0Send(eepromAddr >> 8); // MSB
i2c0Send(eepromAddr & 0xFF); // LSB
i2c0Start();
i2c0SetAddress(addr | 0x01);
unsigned char data = i2c0ReceiveNOACK();
i2c0Stop();
return data;
}
eepromWriteByte(ADDREEPROM, 0, 0xDE);
eepromWriteByte(ADDREEPROM, 1, 0xAD);
uint8_t i1 = eepromReadByte(ADDREEPROM, 0);
uint8_t i2 = eepromReadByte(ADDREEPROM, 1);
But when I'm using this code for writing not work correctly, b/c when I try to save some data, and then try to read it I always get a value 0xFF. And my question is where is a problem? I only want to add I connected pin WP to gnd, and I don't know what could be a problem. And I2C frequency is 100kHz.