Hello,
I'm programming data communication over an I2C bus on the LPC1768. To test the communication, I've looped back the I2C0 bus of the board with I2C1. The I2C0 is supposed to act as the master, and the I2C1 as the slave. However, when sending the data telegram, I always receive a "0x38 Arbitration lost in SLA+R/W or Data bytes" message in the status register, and the process terminates.
void I2C1_config(void)
{
LPC_SC->PCONP |= (1 << 19);
LPC_PINCON->PINSEL1 &= ~0x000003C0;
LPC_PINCON->PINSEL1 |= 0x000003C0;
LPC_I2C1->I2CONCLR = I2C_CON_FLAGS ; //Clear all flags
NVIC_EnableIRQ(I2C1_IRQn);
LPC_I2C1->I2ADR0= 0b10100000;
LPC_I2C1->I2MASK0=0xA0;
LPC_I2C1->I2CONSET |= I2C_CON_I2EN | I2C_CON_AA; //I2C0 enable
LPC_I2C0->I2CONSET |= I2C_CON_STA;
}
void I2C0_config(void)
{
LPC_SC->PCONP |= (1 << 7);
LPC_PINCON->PINSEL1 &= ~0x03C00000;
LPC_PINCON->PINSEL1 |= 0x01400000; // SDA und SCL
LPC_I2C0->I2CONCLR = I2C_CON_FLAGS ; //Clear I2C0CON Registers
LPC_I2C0->I2SCLL = I2SCLL_SCLL; //DutyCicle
LPC_I2C0->I2SCLH = I2SCLH_SCLH;
//PCLK_I2C0=25MHz ,SCLH+SCLL=250, I2Cbitrate=PCLK_I2C0/(SCLH+SCLL)
NVIC_EnableIRQ(I2C0_IRQn); //Interrupt enable
LPC_I2C0->I2CONSET |= I2C_CON_I2EN; //I2C0 enable
I2C1_config();
}
this is my configuration yet
in my interrupthandler for I2C0 I only address the slave
void I2C0_IRQHandler(void){
uint8_t StatValue;
StatValue = LPC_I2C0->I2STAT;
switch (StatValue){
case 0x08:
LPC_I2C0->I2DAT=state_vec[0];
LPC_I2C0->I2CONCLR=0x08;
break;
case 0x38:
LPC_I2C0->I2CONSET=0x20;
LPC_I2C0->I2CONCLR=0x08;
break;
case 0x68:
LPC_I2C0->I2CONSET=0x20;
LPC_I2C0->I2CONCLR=0x08;
break;
}
}
And this is my interrupthandler for I2C1
void I2C1_IRQHandler(void){
switch(LPC_I2C1->I2STAT)
{
case 0x60:
LPC_I2C1->I2CONSET=0x04;
LPC_I2C1->I2CONCLR=0x08;
break;
case 0x70:
LPC_I2C1->I2CONSET=I2C_CON_AA;
LPC_I2C1->I2CONSET=I2C_CON_SI;
break;
case 0x80:
break;
case 0xA0:
LPC_I2C1->I2CONSET=0x04;
LPC_I2C1->I2CONCLR=0x08;
}
}
After I address the slave and clear the I2C0 Interruptflag the I2C0 status is: 0x38 Arbitration lost in SLA+R/W or Data bytes
And the status of the I2C1 is: 0x60 Own SLA+W received; ACK returned
From there i have to restart the process cause of the 0x38 status. Can someone look into it and can tell me what i did wrong. I need to send a data byte after the addressing.