Hi eLin,
Thank you for your updated information.
Customer can use the optimize, actually optimize will decrease the code size, just decrease the code execute time.
On my side, I modify the SDK interrupt handler, and change it to the register control mode, then the ACK&Data time is also decreased.
From my attached code, you can find if don't modify, the executed time is about 12us, but if I use the register control, the time is about 6.8us.
Actually, it is relate to the Handler execute time.
I modify the SDK code in folder: SDK_2.4.1_FRDM-KL43Z\boards\frdmkl43z\driver_examples\i2c\interrupt_b2b_transfer\slave\iar
fsl_i2c.c void I2C_SlaveTransferHandleIRQ(I2C_Type *base, void *i2cHandle) like this:
void I2C_SlaveTransferHandleIRQ(I2C_Type *base, void *i2cHandle)
{
volatile unsigned char Dummy;
if (I2C0->FLT & (I2C_FLT_STOPF_MASK))
{
I2C0->FLT |= (I2C_FLT_STOPF_MASK);
I2C0->S |= (I2C_S_IICIF_MASK);
return;
}
if(I2C0->S & I2C_S_IICIF_MASK)
{
I2C0->S |= I2C_S_IICIF_MASK;
if (I2C0->S & I2C_S_ARBL_MASK)
{
I2C0->S |= (I2C_S_ARBL_MASK);
if (!(I2C0->S & (I2C_S_IAAS_MASK)))
{
return ;
}
}
}
if (I2C0->S & I2C_S_IAAS_MASK)
{
I2C0->C1 &= ~I2C_C1_TXAK_MASK;
if (I2C0->S & I2C_S_SRW_MASK)
{
I2C0->C1 |= I2C_C1_TX_MASK;
I2C0->D = 0x55;
}
else
{
I2C0->C1 &= ~I2C_C1_TX_MASK;
Dummy = I2C0->D ;
}
}
else
{
if (I2C0->S & I2C_S_SRW_MASK)
{
if(I2C0->S & I2C_S_RXAK_MASK)
{
I2C0->C1 &= ~I2C_C1_TX_MASK;
Dummy = I2C0->D;
}
else
{
I2C0->D = 0x55;
}
}
else
{
I2C0->C1 &= ~I2C_C1_TX_MASK;
Dummy = I2C0->D;
}
}
}
This time should meet the customer's demand.
If the customer still want to minimize the time, they need to modify the .s file, just use I2C0_IRQHandler as the Interrupt handler directly.
Don't copy the to I2C0_DriverIRQHandler, then I2C_TransferCommonIRQHandler, then I2C_SlaveTransferHandleIRQ
As you know, enter deep function also need the code execute time, just simplify the code method.
But if the time already meet the customer's demand, it's better use the SDK directly, becuase that code structure is more better, just a little complicated to the code execute time.
I also attached my modified code for your reference.
This picture is SDK code without modification:

This picture is using the register controlled interrupt handler:

Wish it helps you!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------