I2C event handler invoked from inside RTC event handler

Hi, 

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

int main(void)
{

// initialization and configuration .......

while (true)

STS30_I2C_sample();

nrf_delay_ms(1000);

}

}

This works fine. Every 1 second STS30_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 STS30_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 STS30_I2C_sample() function inside it, and this calls for STS30_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 STS30_detect().

When I compare signals in the two cases by logic analyzer, I dont see any difference in signals being sent/received to/from STS30 sensor by nrf_drv_twi_rx() function inside STS30_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