Content originally posted in LPCWare by zoromoth on Thu Mar 14 09:16:20 MST 2013
I wrote the following code for i2c,configured as a slave.The aim is for the slave to first recieve and acknowledge the address request.The address is being acknowledged properly, so i guess my intialization is correct.But the data byte is not being transmitted.I also noticed that the entire i2c module resets after the SI bit is cleared.Can anyone tell me what the problem is
The controller(slave) is LPC1788.
void i2c0init()
{
LPC_SC->PCONP|=(1<<7);
LPC_IOCON->P0_27|=1;//sda
LPC_IOCON->P0_28|=1;//scl
LPC_I2C0->SCLH=300;
LPC_I2C0->SCLL=300;
LPC_I2C0->CONCLR&=0;
LPC_I2C0->CONSET=0x44; //Slave is waiting,si bit set
LPC_I2C0->ADR0|=(0x7<<1);
}
int main(void)
{
i2c0init();//slave i2c
while(1)
{
if( LPC_I2C0->STAT==0xa8 || LPC_I2C0->STAT==0x60 )
{
LPC_GPIO0->DIR=0xffffffff;
LPC_GPIO0->CLR=0xffffffff;
LPC_I2C0->DAT=0x32;
LPC_I2C0->CONCLR|=(1<<3);
}
}