TheThingsIndustries / generic-node-se

Generic Node Sensor Edition
https://www.genericnode.com
Other
110 stars 31 forks source link

Possible external I2C bus issue #210

Open goran-mahovlic opened 3 years ago

goran-mahovlic commented 3 years ago

Summary:

While using library for AS7341 sensor I have noticed that I2C HAL sometimes fails and returns HALL ERROR. That is problematic as at that point I cannot send commands to sensor and this sensor needs to be set into sleep mode via commands. If I do not check HAL fail I end up with higher consumption in sleep mode. And after some time, and wake HAL starts to work - so it is not noticeable by sensor readings. It happens maybe once every 100 wakes, so it is not easy to catch. After adding small delay before HAL_I2C_Mem_Write I get this error really rare https://github.com/goran-mahovlic/generic-node-se/blob/develop/Software/lib/AS7341/AS7341.c#L38 I still did not find why this is happening so I just implemented check for HAL error and if it happens before sensor ends in sleep mode I just do system reset. That way I will know it is still happening, and I am not in risk of high consumption on the device. ...

Steps to Reproduce:

I did not try, but maybe looping HAL_I2C_Mem_Write some external sensor would bring same results.

What do you see now?

...

What do you want to see instead?

...

How do you propose to implement this?

...

Environment:

...

What can you do yourself and what do you need help with?

...

elsalahy commented 3 years ago

Hello @goran-mahovlic ,

Thanks for opening the issue.

First:

I think it is good to mention in the description that this issue is related to the external sensor bus I2C2, and your own personal integration with an external AS7341 sensor.

Second:

HAL_I2C_Mem_Write returns either HAL_OK, HAL_ERROR or HAL_BUSY Any failure to communicate with the external sensor (mainly a timeout) would result in a HAL_ERROR.

Since you are mentioning that:

  1. This maybe happens once every 100 read
  2. The added delay made it rare to catch the fault

It feels like this is an integration issue with the external sensor.

We will do our best to try to reproduce it, but I would appreciate it if you can provide us with more description on the error and the time it takes the sensor to start responding again after an error.