View previous topic :: View next topic |
Author |
Message |
rfreddy
Joined: 03 Jun 2007 Posts: 7
|
Help with 24c256 |
Posted: Sun Jun 03, 2007 7:52 am |
|
|
Hi!, I'm writing an application which uses 8 24c256 I2C EEPROM. I was only able to write in one of them, but all my efforts to write in the others were unsucessful. I know the logic address must match physical address and must follow its control code which is 1010 (0xA?), but when I change the number after the control code my applicattion hangs.
Anybody can show me a working code which uses several of these memories?
Thanks in advance.
Freddy. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sun Jun 03, 2007 9:59 am |
|
|
Remember that on these devices (and on I2C devices in general), the 8bit value here, is setup as:
4bit control code: 3bit address: 1bit R/W
You must not change the bottom bit, and the value on the A0 to A2 lines needs to match the 3bit address. So, if you have the lines wired with 001 (a 1 on A0 only), then the address byte has to change to:
1010 001 0
So you need to double the 'address', before combining it with the byte, or the address will not be understood, and the chip won't respond.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
caduhitec
Joined: 06 Feb 2007 Posts: 3
|
|
Posted: Sun Jun 03, 2007 11:44 am |
|
|
hi dear,
I gesst this way it´s work, let me know.
BOOLEAN I2C_ready(BYTE device) // Possible to device is 0 to 7
{
int1 ack;
i2c_start(); // If the write command is acknowledged,
ack = i2c_write(0xA0 | device << 1); // then the device is ready.
i2c_stop();
return !ack;
}
void i2c_write_byte(BYTE device, long int address, BYTE data) // Possible to device is 0 to 7
{
short int status;
disable_interrupts(GLOBAL);
i2c_start();
i2c_write(0xA0 | device << 1);
i2c_write((address >> 8) &0x1f);
i2c_write(address);
i2c_write(data);
i2c_stop();
i2c_start();
status = i2c_write(0xA0 | device << 1);
while (status == 1)
{
i2c_start();
status = i2c_write(0xA0 | device << 1);
}
i2c_stop();
enable_interrupts(GLOBAL);
}
BYTE i2c_read_byte(BYTE device, long int address) // Possible to device is 0 to 7
{
BYTE data;
disable_interrupts(GLOBAL);
i2c_start();
i2c_write(0xA0 | device << 1);
i2c_write((address >> 8) &0x1f);
i2c_write(address);
i2c_start();
i2c_write(0xA1 | device << 1);
data = i2c_read(0);
i2c_stop();
enable_interrupts(GLOBAL);
return (data);
} |
|
![](templates/subSilver/images/spacer.gif) |
rfreddy
Joined: 03 Jun 2007 Posts: 7
|
Re: Help |
Posted: Mon Jun 04, 2007 11:43 am |
|
|
Hi, thank you both for your timely answers. The code worked great!.
Freddy. |
|
![](templates/subSilver/images/spacer.gif) |
|