I meet some problems during debugging S3KK144 I2C slave.
When the I2C master sends one data to the slave, everything seems OK.
But when sending more than one data, FEF error occurs.
The following is the configuration code and interrupt function, could you help to check whether anything is wrong? Thanks
void I2C_InitSlave()
{
// Reset master
LPI2C0->MCR |= LPI2C_MCR_RST_MASK;
LPI2C0->MCR &= ~LPI2C_MCR_RST_MASK;
LPI2C0->MCR = 0x00;
// Reset slave
LPI2C0->SCR = LPI2C_SCR_RST_MASK;
LPI2C0->SCR &= ~LPI2C_SCR_RST_MASK;
// Enable Recieve interrupt
LPI2C0->SIER = LPI2C_SIER_RDIE_MASK;
// Disable FIFO
LPI2C0->SDER = 0x00;
LPI2C0->SCFGR1 = 0x07;
LPI2C0->SCFGR2 = 0;
LPI2C0->SAMR = LPI2C_SAMR_ADDR0(0x40);
LPI2C0->SAMR |= LPI2C_SAMR_ADDR1(0);
LPI2C0->SCR = LPI2C_SCR_SEN_MASK;
__VECTOR_RAM[VECTOR_INDEX(LPI2C0_Slave_IRQn)] = (DWORD)I2C_SlaveISR;
enable_irq(LPI2C0_Slave_IRQn);
}
void I2C_SlaveISR()
{
static DWORD ulData;
static DWORD ulSsrReg;
ulSsrReg = LPI2C0->SSR;
// Receive data
if(ulSsrReg & LPI2C_SSR_RDF_MASK)
{
ulData = LPI2C0->SRDR;
if(ulData & LPI2C_SRDR_SOF_MASK)
{
m_ucIndex = 0;
}
m_aulRxData[m_ucIndex ++] = ulData & LPI2C_SRDR_DATA_MASK;
}
if(ulSsrReg & LPI2C_SSR_TAF_MASK)
{
LPI2C0->STAR = 0;
}
if(ulSsrReg & LPI2C_SSR_FEF_MASK)
{
LPI2C0->SSR = LPI2C_SSR_FEF_MASK;
}
if(ulSsrReg & LPI2C_SSR_RSF_MASK)
{
LPI2C0->SSR = LPI2C_SSR_RSF_MASK;
}
if(ulSsrReg & LPI2C_SSR_SDF_MASK)
{
LPI2C0->SSR = LPI2C_SSR_SDF_MASK;
}
}
I am glad to hear that it works now. Thanks for sharing the root cause: A register is set error in the interrupt. Anything is ok after revised the firmware.