Hello!
This is my first time using a Nordic product and I'm still learning the basics. I am adapting the TWI Sensor example and I'm trying to read data back from an accelerometer. Unfortunately, it's jumping out of a function before it should (and running right past the breakpoints). I assume it's an optimization setting but I wasn't sure.
Below is my basic code:
bool ADXL355_check_status(int address)
{
ret_code_t err_code;
m_xfer_done = false;
uint8_t reg[1] = {WHO_AM_I_Register};
err_code = nrf_drv_twi_tx(&m_twi, address, reg, sizeof(reg), false);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);
m_xfer_done = false;
err_code = nrf_drv_twi_rx(&m_twi, address, &m_sample, sizeof(m_sample)); <----- Jumps FROM here
APP_ERROR_CHECK(err_code); <----------------- Never makes it to this line
if(m_sample==WHO_AM_I_RESPONSE)
return true;
else
return false;
}
/**
* @brief Function for main application entry.
*/
int main(void)
{
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_INFO("\r\nTWI sensor example started.");
NRF_LOG_FLUSH();
twi_init();
//LM75B_set_mode();
ADXL355_check_status(ADXL355_I2C_ADDRESS);
while (true)
{
nrf_delay_ms(500); <---------------------- Jumps TO here
do
{
__WFE();
}while (m_xfer_done == false);
//read_sensor_data();
NRF_LOG_FLUSH();
}
}
As I noted above, it runs:
err_code = nrf_drv_twi_rx(&m_twi, address, &m_sample, sizeof(m_sample));
and never makes it to:
"APP_ERROR_CHECK(err_code); " line.
It jumps straight down to:
nrf_delay_ms(500);
The good news is it looks like it's actually sending and receiving the data correctly. Unfortunately, it's not getting to the data check at the end to provide the expected bool output.
Any idea what I can do to resolve this? Any help you can provide would be greatly appreciated. Thanks!