Communicate with sensor in timer interrupt occurs issue

Hi,

My product uses two sensors, and S113 on nrf52833

I need to communicate and compute data before to update my ble caracteristic.

Sensor 1 takes 45ms to do this tasks ( communication + computation + update ble carac).

Sensors 2 takes 16ms.

I do this periodically with timer interrupt each 100ms for Sensor 1, and each second for sensor 2.

App Timer interrupt is set to 6 in my sdk_config.h.

I remark that ble connexion crash when sensor 1 timer happen. I guess it comes from the fact i'm blocking the software and softdevice or may be others tasks can not execute.

So i decided to use a flag set in timer, and execute sensor communication and ble update in the main loop, by checking the flag.

Now it works better.

I would like confirmation it is the issue and or reference value of the time we could spend in interrupt to aovid issue. 

Is also my solution the good way to proceed? Is there a more professionnal way to do it ?

Thank you very much !

  • Hi,

    Do you really nee to busy wait (block) for a long time? If you could avoid it, that would be better. If not, you should at least make sure you don't to it in an interrupt. Instead, do it from your main loop. Either by some mechanism you decide on your self, or using something like the app scheduler, which is designed for precisely this.

  • Hi Einar,

    So i understand that i did well by checking the flag set in timer interrupt in the main, and then do the job in the main.

    I can not really avoid the 46ms and 16ms because it is the time it takes to really communicate with sensors and compute their raw data.

    Concerning scheduler, i will start by test this simple and light "flag mecanism" and is i see i miss some reading because the timer between two interupt is too short compared to the reading of the flag, i will study the handler option. 

    Thank you !

Related