AnsweredAssumed Answered

[NHS3100][app_demo_dp_tlogger] my I2C not working

Question asked by Arna Lee on Mar 19, 2018
Latest reply on Mar 28, 2018 by Arna Lee

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

Outcomes