I2C slave bug in fsl_i2c.c

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I2C slave bug in fsl_i2c.c

1,084 Views
michals
Contributor II

There appears to be a bug in fsl_i2c.c (latest SDK for MCUXpresso for KL17 as of 2018-07-05). I have implemented I2C slave on KL17 and the code works fine in blocking mode but does not work in interrupt driven (specifically, when slave is receiving incoming data. Slave transmit out data works fine). I traced this down to this snipped of code in:

void I2C_SlaveTransferHandleIRQ(I2C_Type *base, void *i2cHandle)

#ifdef I2C_HAS_STOP_DETECT
/* Check stop flag. */
if (status & kI2C_StopDetectFlag)
{
I2C_MasterClearStatusFlags(base, kI2C_StopDetectFlag);

/* Clear the interrupt flag. */
base->S = kI2C_IntPendingFlag;

/* Call slave callback if this is the STOP of the transfer. */
if (handle->isBusy)
{
xfer->event = kI2C_SlaveCompletionEvent;
xfer->completionStatus = kStatus_Success;
handle->isBusy = false;

if ((handle->eventMask & xfer->event) && (handle->callback))
{
handle->callback(base, xfer, handle->userData);
}
}
if (!(status & kI2C_AddressMatchFlag))
{
return;
}
}
#endif /* I2C_HAS_STOP_DETECT */

The problem is that when, IRQ is triggered on 'stop' detected, there is still a byte in the data register (data in I2C->D and TFC flag on). However, that byte is never processed because of the last 'if' statement above. I2C->S register does not show 'kI2C_AddressMatchFlag' (IAAS) so the IRQ handler exits and drops last byte. Commenting out that last 'if' statement gets slave receive working using fsl_i2c.c.

Labels (1)
3 Replies

743 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Michals:

Thanks for your feedback. I will try to reproduce your issue on my side and get it back to you when I have results

Have a nice day!

Regards

Daniel

0 Kudos

743 Views
juanjovicente
Contributor II

Hi Daniel,

Any news on this topic?

Regards,

Juanjo

0 Kudos

743 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Juanjo:

This issue is documented in an errata:

" Title:

I2C: Slave does not hold bus between byte transfers and may result in lost data

Errata Description:

When the I2C module is used as a slave device, the bus is not held by the slave between byte transfers. If the I2C slave I2C_D register and the data buffer are full, incoming data from an I2C master will overwrite data in the data buffer.

Errata Workaround:

When configured as a slave, the delay in processing incoming bytes should be minimized. Delay can be minimized by the use of DMA or increased interrupt priority."

 Errata link: 

https://www.nxp.com/products/processors-and-microcontrollers/arm-based-processors-and-mcus/kinetis-c...

I have reported this issue to develop team.   The status is in progressing.

Regards

Daniel

0 Kudos