Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

twi_sensor example hangs on nRF52840 DK

I'm using nRF5_SDK_15.3.0_59ac345 with a nRF52840 DK (v1.0.0 PCA10056), building and debugging using IAR 8.32.3 (which is working fine).  I build and debug an unmodified twi_sensor example app, the nrf_drv_twi_init() call returns no error, but the app hangs waiting for the first twi transmission to complete. Specifically, in the following block of code, nrf_drv_twi_tx() returns immediately (because it's in non-blocking mode), but the subsequent while loop never falls through, because the twi_handler() is never called.

uint8_t reg[2] = {LM75B_REG_CONF, NORMAL_MODE};
err_code = nrf_drv_twi_tx(&m_twi, LM75B_ADDR, reg, sizeof(reg), false);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);

I've also reproduced this problem by modding twi_sensor to operate in blocking mode; in this case, nrf_drv_twi_tx() never returns.

I don't have the requisite I2C device connected to the nRF52840 DK, but that shouldn't matter; if the I2C device isn't present, the TWI interface should read a NACK and nrf_drv_twi_tx() should return with an error code.

Parents
  • nrf_drv_twi_tx() never returns

    So where, exactly, is it getting stuck?

  • The project I'm referencing is the twi_sensor example project that Nordic distributes with the nRF5 SDK, so you should be able to reproduce this with an nRF52840 DK. 

    As I mentioned, the code is getting stuck in the while loop of the code snippet I provided:

          while (m_xfer_done == false);

    This is in line 96 of main.c, in the function LM75B_set_mode(). It's getting stuck in that line because m_xfer_done is never getting set to true, which is happening because the twi_handler() callback is never getting called (it should always be called when the driver is in non-blocking mode).

    Also, if I modify the twi_sensor example code such that the twi_handler() callback is not passed to nrf_drv_twi_init() -- doing this places the driver in blocking mode -- then the code gets stuck in the nrf_drv_twi_tx() call in the code snippet I provided, line 94 of main.c. This is also an incorrect behavior; in blocking mode, nrf_drv_twi_tx() should always return if the I2C slave NACKs, which is what should happen if no such device is attached to the I2C bus.

  • I meant when you've modified it to work in blocking mode, where is it sticking within nrf_drv_twi_tx()  ?

Reply Children
No Data
Related