This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Getting NRF_ERROR_INVALID_STATE after executing function nrf_ble_qwr_conn_handle_assign() when managing TWI

Hi,

I'm using the NRF52832, as peripheral, to read data from a HTS221 sensor via I2C.

I'm using the TWI_sensor module following this example, but I want it to enable and disable this module to decrease the device consumption.

I've defined a timer to manage the sensor reads every 10 seconds as follows:

1. 1 second before reading, it enables the sensor's power supply and inits the module

2. It reads the sensor register to save temperature

3. 1 seconds after reading, it uninits the module and disables the sensor's power supply

I've used 1 second between each action to ensure the last action is done before the next one.

if (sensor_action == 1){
      sensor_action = 0;
      nrf_gpio_pin_set(GPIO_DCDC_ENABLE);
      twi_config();
    }
    else if (sensor_action == 2){
      sensor_action = 0;
      hts221_read();
    }
    else if (sensor_action == 3){
      sensor_action = 0;
      nrf_twi_mngr_uninit(&m_nrf_twi_mngr);
      nrf_gpio_pin_clear(GPIO_DCDC_ENABLE);
    }

If I keep the module enabled continously it works well, but when I try to do this process, it doesn't read the sensor registers.

In addition, when I use this process and I try to connect the peripheral to a central, I get NRF_ERROR_INVALID_STATE after function nrf_ble_qwr_conn_handle_assign() in ble_evt_handler.

I dont't know how changes in TWI module affect the BLE module.

  • In addition, when I use this process and I try to connect the peripheral to a central, I get NRF_ERROR_INVALID_STATE after function nrf_ble_qwr_conn_handle_assign() in ble_evt_handler.

     Have you tried to do any debugging to figure out why this is returned? Where/what function inside nrf_ble_qwr_conn_handle_assign() returns NRF_ERROR_INVALID_STATE? Is it a softdevice call? If not, what function inside that function again caused it to return NRF_ERROR_INVALID_STATE?

    Hint: if it is VERIFY_MODULE_INITIALIZED(), then this is a macro returning NRF_ERROR_INVALID_STATE if the module is not initialized. MODULE_INITIALIZED is defined on line 49 in nrf_ble_qwr.c:

    #define MODULE_INITIALIZED      (p_qwr->initialized == NRF_BLE_QWR_INITIALIZED).

    If not initialized, you need to call nrf_ble_qwr_init() at some point before you call nrf_ble_qwr_conn_handle_assign().

     

    If I keep the module enabled continously it works well, but when I try to do this process, it doesn't read the sensor registers.

     What do you mean by this? Is hts221_read() called? I assume it doesn't return any return value? Where did you find this function? I guess it uses the TWI drivers in the end. Do you check any return values to see whether it was able to send the read message? Have you tried to analyze the TWI pins using a logic analyzer? Does any data occur on the TWI pins?

    Best regards,

    Edvin

Related