- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want a callback function that is called once the I2C master is done sending all the bytes. I came across 2 options that I maybe able to use -
I2C_1_I2C_ISR_ExitCallback() or I2C_1_SetMasterInterruptMode(I2C_1_INTR_MASTER_I2C_STOP) or I2C_1_I2C_MSTAT_RD_CMPLT;
What is the difference between the two? And which one should I be using?
Also, I need to set some flags indicating slave's status. For this I also came across I2C_1_I2C_SSTAT_RD_CMPLT (& other flag bits), I2C_1_I2C_SlaveCompleteCallback and I2C_1_SetSlaveInterruptMode. What is the differnce between all these methods?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello SaGh_4441651
The callback function (I2C_1_I2C_ISR_ExitCallback()) is the correct method to check. The I2C component will return I2C_1_I2C_MSTAT_RD_CMPLT for I2C_1_I2CMasterStatus() once the read is complete. Hence, the callback function must include an if statement like
if (0u == (I2C_1_I2CMasterStatus() & I2C_1_I2C_MSTAT_RD_CMPLT))
{
}
Another method is to poll I2C_1_I2C_MSTAT_RD_CMPLT to check if the read is complete. This can be done by continuously checking the return status of I2C_1_I2CMasterStatus().
However, interrupt method is a better solution.
Thanks and regards
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello SaGh_4441651
The callback function (I2C_1_I2C_ISR_ExitCallback()) is the correct method to check. The I2C component will return I2C_1_I2C_MSTAT_RD_CMPLT for I2C_1_I2CMasterStatus() once the read is complete. Hence, the callback function must include an if statement like
if (0u == (I2C_1_I2CMasterStatus() & I2C_1_I2C_MSTAT_RD_CMPLT))
{
}
Another method is to poll I2C_1_I2C_MSTAT_RD_CMPLT to check if the read is complete. This can be done by continuously checking the return status of I2C_1_I2CMasterStatus().
However, interrupt method is a better solution.
Thanks and regards
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey,
Thank you for your response. So I if want to check the same for a slave device, should I be using the same callback and then instead check for I2C_1_I2C_SSTAT_RD_CMPLT? How do I check if the slave is busy i.e. with the flag I2C_1_I2C_SSTAT_WR_BUSY? Do I have to poll this flag to check slave's status? Because I am assuming the callback is called once the ISR is done executing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi SaGh_4441651
Yes. Depending on the slave application, I2C_1_I2C_SSTAT_RD_CMPLT or I2C_1_I2C_SSTAT_WR_CMPLT must be checked to see if the slave is free.
You can either poll (in main itself) or you can check the condition and wait in the end of ISR in callback function.
Thanks and regards
Harigovind
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would recommend not to wait in an interrupt handler, system might stall.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. This is true. The implementation suggested was to check the interrupt cause - I2C_1_I2C_SSTAT_RD_CMPLT or I2C_1_I2C_SSTAT_WR_CMPLT- using conditional statements.
Thanks and regards
Hari