[SOLVED] AT24C256 not working write mode

Status
Not open for further replies.

mi14chal

Newbie level 5
Joined
Oct 30, 2010
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
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:
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.
 

That doesn't seem right, according to the manual (assuming A1=A0=0) the address should be

10100000 for write (0xA0)
10100001 for read (0xA1)
 
Oh thanks now it works. I used an example code from another website and I thought there was a good address so I didn't check it. Thanks again for helping.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…