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

TWI read from multiple sensors return err 17

Hi,

I'm reading temperature and humidity from 2 sensors in my system

At some point in time during a quick and dirt check the system has been proven working fine and I could read temp and humidity values (so no error in hw)

Then I cleanup the code and nothing works anymore

Reading first sensor (temperature) is fine but 2nd read from humidity sensor return ERR 17 (should be NRF_ERROR_BUSY = driver not ready for new transfer)

In my main code I have TWI TX calls to start transmission and then I'm waiting for TWI HANDLER to complete transfer

// Enter main loop.
for (;;)
{
  switch (twi_case_main) {
      case TWI_WAIT_MCP9808:
        if (m_xfer_done == true) {
          twi_case_main = TWI_MCP9808;
        }
      break;
      case TWI_MCP9808:
        twi_case_var = TWI_MCP9808;  // set case for twi_handler
        reg[0] = MCP9808_RA_TEMP;
        twi_err_code = nrf_drv_twi_tx(&m_twi_sensors, MCP9808_ADDR, reg, sizeof(reg), false);  
        APP_ERROR_CHECK(twi_err_code);
        twi_case_main = TWI_WAIT_HTDU21D_RH;
      break;

      case TWI_WAIT_HTDU21D_RH:
        if (m_xfer_done == true) {
          twi_case_main = TWI_HTDU21D_RH;
        }
      break;
      
      case TWI_HTDU21D_RH:
        twi_case_var = TWI_HTDU21D_RH;  // set case for twi_handler
        reg[0] = TRIGGER_HUMD_MEASURE_NOHOLD;
        twi_err_code = nrf_drv_twi_tx(&m_twi_sensors, HTDU21D_ADDRESS, reg, sizeof(reg), false);  
        APP_ERROR_CHECK(twi_err_code);
        twi_case_main = TWI_IDLE;
      break;

      case TWI_IDLE:
        if (m_xfer_done == true) {
          twi_case_var = TWI_WAIT_MCP9808;
        }
      break;

      default:
        twi_case_var = TWI_MCP9808;
      break;
  }
}

In my twi handler

/**

  • @brief TWI events handler. */ void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context) {
    // some variables here

    switch (twi_case_var) { // TWI events sequence is initiated by main task with a nrf_drv_twi_tx() call and complete with the following sequence case TWI_MCP9808: switch(p_event->type) { case NRF_DRV_TWI_TX_DONE: /* Read 2 bytes from the specified address. */ err_code = nrf_drv_twi_rx(&m_twi_sensors, MCP9808_ADDR, data, sizeof(uint8_t) * 2, false); APP_ERROR_CHECK(err_code); break;

         case NRF_DRV_TWI_RX_DONE:
           // Mask out flags and clean up sign bit
           temp = data[0] << 8 | data[1];
           temperature = temp * some_k; // temperature
    
           m_xfer_done = true;  // tell main app sensor read has been complete
         break;
    
       default:
         break;        
     }   
    

    break;

    case TWI_HTDU21D_RH: switch(p_event->type) { case NRF_DRV_TWI_TX_DONE: /* Read 3 bytes from the specified address. */ err_code = nrf_drv_twi_rx(&m_twi_sensors, HTDU21D_ADDRESS, data, sizeof(uint8_t) * 3, false); APP_ERROR_CHECK(err_code); break;

         case NRF_DRV_TWI_RX_DONE:
           // Mask out flags and clean up sign bit
           temp = data[0] << 8 | data[1];
           humidity1 = temp * some_k; // humidity
    
           m_xfer_done = true;  // tell main app sensor read has been complete
         break;
    
         default:
         break;        
     }
    

    break; } }

I'm getting err 17 when I try to read from humidity sensor What am I doing wrong?

Thanks

Parents
  • Never mind

    I had to fix some bugs in my code but the main problem is my humidity sensor (HTU21D) that release the bus between tx and rx sequence and this behavior confuse twi driver.

    Using "blocking" read command solve the problem

Reply
  • Never mind

    I had to fix some bugs in my code but the main problem is my humidity sensor (HTU21D) that release the bus between tx and rx sequence and this behavior confuse twi driver.

    Using "blocking" read command solve the problem

Children
No Data