Hi,
I am trying to use APP_TIMER to detect if a sensor isn't responding to I2C Commands. I created and started the timer with the following steps. The project is based on Thread "mtd_coap_client" project.
- Enabled Low-Frequency clock,
- Created a timer and started it.
- Send a command to a sensor on I2C Bus and wait for it to Acknowledge. Sleep during wait.
Here's the code:
//Read the Datasheet for more inforamtion on Configuration Register.
uint8_t transmitBuffer[3] = {OPT3004_REGISTER_CONFIGURATION, 0xCC, 0x09};
TWITransmitCompleted = false;
startTimeoutTimer(1000);
ret_code_t err_code = nrf_drv_twi_tx(&sensorsTWIInstance, OPT3004_DEVICE_ADDRESS, transmitBuffer, 3, false);
if(err_code != NRF_SUCCESS) {
NRF_LOG_ERROR("OPT3004 -> OPT3004Initialisation. Error while setting config register. Error: %d", err_code);
NRF_LOG_FLUSH();
return err_code;
}
while(TWITransmitCompleted == false && timeoutTimerElapsed == false) {
// Make sure the event register is cleared
__SEV();
__WFE();
//Enter SYSTEM ON Sleep Mode
__WFE();
}
The problem I am facing is, if I have:
while(TWITransmitCompleted == false && timeoutTimerElapsed == false) {
// Make sure the event register is cleared
__SEV();
__WFE();
//Enter SYSTEM ON Sleep Mode
__WFE();
},
The control never goes to timeout handler. If I remove while(), control goes to timeout handler.
Can you please help me understand what's causing this?