This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI Stuck in nrf_twim_event_check using peripheral sensor.

Greetings, we're currently working in an application where we need to connect different peripherals to a nrf52832 for a wearable device. Each of these peripherals uses a different communication protocol, we are using the following peripherals with the respective protocol and SDK 14.1 instance:

  • ADS1292R - SPI2 -Interrupt Priority 6
  • MAX30101 - TWI0 - Interrupt Priority 7
  • OpenLog - UART0

We've managed receive data and store it in an SD card successfully during lab conditions, but when we field test the device we are experiencing errors due to the TWI communication. If there is a situation where, for some reason, the MAX30101 is disconnected from the system the MCU will stay in an infinite loop checking for events "nrf_twim_event_check". The idea is that if for some reason this peripheral gets disconnected, and re plugged, the system would be able to recover by itself and continue its operation without the need of a complete reset. We've read various questions here in the devzone and some doubts still remain.

  1. Is there any way to exit this while condition?
  2. If we use the non-blocking characteristic could this problem be avoided? If so, what are the differences with the blocking one? How is it implemented?
  3. Does nrf_twim_event_check has a timeout somewhere?

Thanks beforehand for your help.

Best Regards Samuel Escobar

  • Hi,

    1. What events is the function waiting for? Naturally it will only exit when an event that meets its requirements occurs. If no such event can be generated when you disconnect your device then it will never exit.
    2. If you configure your TWI in blocking mode the TWI drivers will wait in while() loops until each TWI transfer is complete. That is probably what happens when you get stuck with nrf_twim_event_check(). I think a non-blocking solution is the way to go. It gives you more control, you can handle all events in your own event handler, and you can implement timeout mechanisms.
    3. Unfortunately not.
  • I implemented an escape condition within the nrf_twim_event_check cycle based on number of iterations. If the system iterated more than N times in the same while cycle then if would break and returned to its previous task. I guess that for my application this actually works but the correct way should be using the non-blocking twi feature. I appreciate your help and I'm going to move forward to implement twi in the non blocking way.

Related