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
  • Hi,

    You are not using the RTC configured interrupt priority defined in your sdk_config.h file, so the priority is likely set to 0 (or whatever else is stored in the area where rtc_config is placed in RAM). You can read out the actual priorities by looking at the NVIC->IPRx registers:

    To use the priority from your sdk_config.h file, you can assign the default config to the variable like this:

    nrf_drv_rtc_config_t rtc_config = NRF_DRV_RTC_DEFAULT_CONFIG;

    Best regards,
    Jørgen

Reply
  • Hi,

    You are not using the RTC configured interrupt priority defined in your sdk_config.h file, so the priority is likely set to 0 (or whatever else is stored in the area where rtc_config is placed in RAM). You can read out the actual priorities by looking at the NVIC->IPRx registers:

    To use the priority from your sdk_config.h file, you can assign the default config to the variable like this:

    nrf_drv_rtc_config_t rtc_config = NRF_DRV_RTC_DEFAULT_CONFIG;

    Best regards,
    Jørgen

Children
Related