
how to configure multiple slave devices in I2C with the LPC2148

Hi everyone,
I have the following configuration code to work with the I2C in the LPC2148.
I need to use three memory slave devices of the 24LC256 series.
I made the following adjustment but it only works for memory in the 0xA0 address
for the other positions it does not work.
//First Memory 0xA0 //Second Memory 0xA2 //Third Memory 0xA4 const char EEPROM_STACKMEMORIAS[]={0xA0,0xA2,0xA4}; char I2C_ReadFromEEPROM (uint32 u32startAddr, uint8 *u8ptr2arr, uint32 u32len, uint8 MemorySelect)
{
uint32 u32i;
// Check for upper limit
if (u32startAddr + u32len > EEPROM_SIZE)
return 0;
for (u32i=0;u32i<u32len;u32i++)
{
I2C0CONSET = 0x20;// Start set
if (!I2C_WaitStatus(0x08)){// 0x08: ready for device address
return 0;
}
I2C0DAT= EEPROM_STACKMEMORIAS[MemorySelect];// addr[0]=0 means I2C write
I2C0CONCLR = 0x2C;// clear all except I2EN
if (!I2C_WaitStatus(0x18))// 0x18: ready for data byte
return 0; ....continue } char I2C_WriteToEEPROM (uint32_t u32startAddr, uint8 *u8ptr2arr, uint32_t u32len, uint8 MemorySelect)
{
uint32_t u32i,u32j;
// Check for upper limit
if (u32startAddr + u32len > EEPROM_SIZE)
return 0;
// write data byte wise
for (u32i = 0; u32i < u32len; u32i++)
{
I2C0CONSET = 0x20;// Start set
if (!I2C_WaitStatus(0x08)){// 0x08: ready for device address
return 0;
}
I2C0DAT= EEPROM_STACKMEMORIAS[MemorySelect];// addr[0]=0 means I2C write
I2C0CONCLR = 0x2C;// clear all except I2EN
if (!I2C_WaitStatus(0x18))// 0x18: ready for data byte
return 0; ....Continue... }

Are you sure that the other memory chips have their addresses set correctly?

I checked more slowly and carefully and had a pin in the air.
check the code again and it works correctly. Thanks for the help.

Since you did not include the calling function, hard to see if MemorySelect is set to something other than 0.
Have you put in slime printf's to see if MemorySelect is being set correctly?

