I2C event handler invoked from inside RTC event handler

Hi, 

I have developed attached code for I2C communication with temperature sensor. The main function I2C_sample() checks whether sensor is detected by detect() and then performs a temperature measurement. The code is initially written by placing I2C_sample() inside the main function with a delay of 1second like below: 

This works fine. Every 1 second detect() and other I2C functions are called and they invoke twi_handler during I2C communication. 

For power saving purposes, I have added the code for an RTC low frequency low power timer counter and its handler into my original code and moved I2C_sample() function into my timer handler function rtc_handler(). During debugging I can see rtc_handler() is called after 1 second, then it calls I2C_sample() function inside it, and this calls for detect() function. This is where the problem happens. Now I dont see twi_handler being called anymore, and my code get stuck in line while(m_xfer_done == false) of function detect().

When I compare signals in the two cases by logic analyzer, I dont see any difference in signals being sent/received to/from sensor by nrf_drv_twi_rx() function inside detect(). So I think maybe there is issue calling twi_handler from inside rtc_handler. 

Please see my code below. I appreciate if you can tell me what the issue could be. 

Thanks

Parents Reply Children
No Data
Related