Hi Sir,
I am using NHS3100 connected with an acceleration sensor (LIS3DH) using I2C interface.
But it is not working properly.
Here is the pin connection according to the attached "NHS3100 schematic.png":
------------------
VCC: VDDBAT (3.3V)
GND: GND
SDA: PIO5 --- P05
SCL: PIO4 --- P04
------------------
I am using "app_demo_dp_tlogger" to add my I2C:
1, Init I2C
2, use "Chip_I2C_MasterSend" and Chip_I2C_MasterRead to send/read data to/from sensor.
But it didn't get anything.
Here is my printf logs:
-----------
Sensor_Init for I2C...
Sensor_WriteReg slaveAddr 0x32, reg_addr 0x20, TxData 0x57
Chip_I2C_MasterSend slaveAddr 0x32, txBuff: 20 57
Chip_I2C_MasterTransfer
Chip_I2C_EventHandlerPolling: I2C event 3
Chip_I2C_EventHandlerPolling: I2C event 1
Chip_I2C_EventHandlerPolling: I2C transfer status 4
-------------------
****** TEST1 ****** Initialize the Event Handler and enable the I2C interrupt ******************************************************************
--- code snippet ---
Chip_I2C_SetMasterEventHandler(I2C0, Chip_I2C_EventHandler);
NVIC_EnableIRQ(I2C0_IRQn);
---
From my observation, the routine stuck in the while statement in the funciton "Chip_I2C_EventHandler":
---
/* Wait for the status to change */
while (*stat == I2C_STATUS_BUSY) {
}
---
I didn't see I2C_STATUS_DONE which will be set in the function "I2C0_IRQHandler" => "Chip_I2C_MasterStateHandler" as my own understand.
****** TEST2 ****** Initialize the Event Handler Polling based ***************************************************************
--- code snippet ---
Chip_I2C_SetMasterEventHandler(I2C0, Chip_I2C_EventHandlerPolling);
------
From my observation, the routine stuck in the while statement in the funciton "Chip_I2C_EventHandlerPolling":
---
/* Call the state change handler till xfer is done */
while (*stat == I2C_STATUS_BUSY) {
if (Chip_I2C_IsStateChanged(id)) {
Chip_I2C_MasterStateHandler(id);
}
---It looks the if condition was always not met.
I tried my best to debug the two test but I am still confused.
Could you help me to review my code and analysis to see if anything wrong?
Attached my working space and screenshots, and I2C operation from the sensor LIS3DH data sheet.
It would be great appreciated if anyone can help me.
many thanks,
Arna
Hi Kan,
Thank you so much for your update.
You are right for the usage of the API "Chip_I2C_MasterCmdRead", I think so.
So the problem is got back to my first case which was mentioned in my previous comment.
As below, can you review again anything wrong?
Appreciated if you have any advice.
Thanks.
1, ***
"Chip_I2C_MasterCmdRead" is provided by the lib i2c_nss. As the function explain:
/* Transmit one byte and receive an array of bytes after a repeated start condition is generated in Master mode.
* This function is useful for communicating with the I2C slave registers
*/
And here is from my sensor's data sheet as below, so I think this API can be use to read my I2C slave device register and it DID. As my understanding, "Chip_I2C_MasterCmdRead" is equivalent to "Chip_I2C_MasterSend" then "Chip_I2C_MasterRead".
The problem is what I mentioned in my previous reply,
---
1.1 send data to I2C slave to get the register data of the sensor by call "Chip_I2C_MasterCmdRead";
1.2 send data to I2C slave to write the register of the sensor by call "Chip_I2C_MasterSend";
1.3 send data to I2C slave to get the register data of the sensor again by call "Chip_I2C_MasterCmdRead";
---
If I just have only item 1.1 (or 1.2, or 1.3) to test, it is ok for the correct operation and result.
But when I have the three items to test together, it is failed to operate the item 1.2 or item 1.3 for the results.
The API function never return for item 1.2 or item 1.3 and it looks the stat is always I2C_STATUS_BUSY from my observation.
Thanks,
Arna
Hi Kan,
1, ***
"Chip_I2C_MasterCmdRead" is provided by the lib i2c_nss. As the function explain:
/* Transmit one byte and receive an array of bytes after a repeated start condition is generated in Master mode.
* This function is useful for communicating with the I2C slave registers
*/
And here is from my sensor's data sheet as below, so I think this API can be use to read my I2C slave device register and it did. As my understanding, "Chip_I2C_MasterCmdRead" is equivalent to "Chip_I2C_MasterSend" then "Chip_I2C_MasterRead".
The problem is what I mentioned in my previous reply,
---
1.1 send data to I2C slave to get the register data of the sensor by call "Chip_I2C_MasterCmdRead";
1.2 send data to I2C slave to write the register of the sensor by call "Chip_I2C_MasterSend";
1.3 send data to I2C slave to get the register data of the sensor again by call "Chip_I2C_MasterCmdRead";
---
If I just have only item 1.1 (or 1.2, or 1.3) to test, it is ok for the correct operation and result.
But when I have the three items to test together, it is failed to operate the item 1.2 or item 1.3 for the results.
The API function never return for item 1.2 or item 1.3 and it looks the stat is always I2C_STATUS_BUSY from my observation.
2, ***
Anyway, I tried as what you adviced but the same phenomenon happened.
---
Hi Arna,
Thanks for the information! I think the cause is due to there is a repeat start condition during the process, so you should use Chip_I2C_MasterCmdRead(), which is transmiting one byte and receive an array of bytes after a repeated start condition is generated in Master mode. and you could not use a combination of Chip_I2C_MasterSend() and Chip_I2C_MasterRead() to replace Chip_I2C_MasterCmdRead(), because there is no repeat start condition in that case.
Hope that makes sense,
Best Regards,
Kan
Hi Kan,
I printf some debug logs and found sometimes I2C0_IRQHandler called but sometimes NOT.
Now I can read/write the register of the sensor by calling the I2C API funciton "Chip_I2C_MasterCmdRead"/"Chip_I2C_MasterSend" respectively.
But the problem I met is that I canNOT operate the I2C by calling the API functions above repeatedly.
My test items/steps are:
If I just have only item 1 (or 2, or 3) to test, it is ok for the correct operation and result.
But when I have the three items to test together, it is failed to operate the item 2 or item 3 for the results.
The API function never return for item 2 or item 3 and it looks the stat is always I2C_STATUS_BUSY from my observation.
Any restriction for the I2C API using?
Thanks,
Arna
Hi Arna,
Why using Chip_I2C_MasterCmdRead()? You should use Chip_I2C_MasterRead(). Just as below:
I think your issue is related with your driver implementation, please kindly check on your side. You should have the SDK code in the following link, right?
https://www.nxp.com/webapp/Download?colCode=RELEASE-MRA2-NHS3100&appType=license
Best Regards,
Kan
Hi Arna,
Have you set a breakpoint in I2C0_IRQHandler() but it never hit? Please help to clarify.
Thanks for your patience!
Best Regards,
Kan