Hello Sirs,
I am studying NHS3100 board kit.
I want to add my motion sensor with I2C interface.
I read some document and it is said that "The user of the I2CIO module only needs to use the API functions below to have full I2C communication. "
I tried my test and the code snippet based on "app_demo_dp_tlogger" is below but it does NOT work.
And I have already linked the mods "i2cio" into my project.
---
Hi Kan,
I tried to debug with breakpoints as below.
And here is my test code snippet ------------
Hi Arna,
To debug I2C, you'd better do with an I2C logic analyzer, or at least an oscilloscope to check if the waveform on I2C SCL and SDA lines is what you expected, and you may also check the data sheet of the I2C device you were handling, if the reading process is correct for that device.
Hope that helps,
Best Regards,
Kan
Hi Kan,
Thank you for more comment.
It makes me more clear to undstand the whole thing.
As my understanding,
Once the master transfer done, the status shoud be set as "I2C_STATUS_DONE". Am I right?
And I see it would happen in two cases as below:
1. -# Interrupt based handling makes use of #Chip_I2C_EventHandler handler.
I2C0_IRQHandler => Chip_I2C_MasterStateHandler => handleMasterXferState => change "xfer->status" to “I2C_STATUS_DONE” once master transfer done;
2. -# Polling based handling makes use of #Chip_I2C_EventHandlerPolling handler.
Chip_I2C_EventHandlerPolling => Chip_I2C_MasterStateHandler => handleMasterXferState => change "xfer->status" to “I2C_STATUS_DONE” once master transfer done.
Is it right?
And if the stat is always I2C_STATUS_BUSY, the while condition is always met and the function is never return.
So I am confused why the stat was not changed.
------
Thanks,
Arna
Hi Arna,
Yes, your understanding is right. I2C_STATUS_DONE is set in handleMasterXferState(), which is called in I2C0_IRQHandler() or Chip_I2C_EventHandlerPolling(), but what ever you used for the event handler, you may just set a breakpoint at the following line:
you may know if this state is set during your test, there is no printf() needed for that purpose.
Hope that helps,
Best Regards,
Kan
Hi Kan,,
Thank you for your reply.
I set "Quickstart -> Quick Settings -> Set library/header type => Redlib (semihost)" to use standard printf function.
1. "It is not recommended using printf() in an interrupt based handler"
=> Is it ok if I use polling event handler "Chip_I2C_SetMasterEventHandler(I2C0, Chip_I2C_EventHandlerPolling)" instead of event handler interrupt based "Chip_I2C_SetMasterEventHandler(I2C0, Chip_I2C_EventHandler)"?
2. "It would be better if you use an I2C analyzer to trace the data transaction."
=> How to do that? Any user manual?
Thanks,
Arna
Hi Arna,
Sorry for the misunderstanding, what I mean is Printf() is not recommended using in an ISR, but ok if you put it in Chip_I2C_EventHandlerPolling() or Chip_I2C_EventHandler(). and from the log, the I2C seems work well as the state changing shows it starts from I2C_EVENT_LOCK to I2C_EVENT_UNLOCK, it means the master transfer is complete, so it should no be stuck in the while loop, the reason why you didn't see I2C_STATUS_DONE is due to this state is only set in Chip_I2C_MasterStateHandler(), which is called in Chip_I2C_EventHandlerPolling(), not Chip_I2C_EventHandler().
The I2C analyzer is just a logic analyzer for I2C protocol. something like Beagle I2C/SPI Protocol Analyzer - Total Phase .
Hope that helps,
Have a great day,
Kan
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Arna,
How did you get the log? It is not recommended using printf() in an interrupt based handler, cause it affects the timing. It would be better if you use an I2C analyzer to trace the data transaction.
Have a great day,
Kan
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------