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

nrf_drv_twi_rx return busy

I'm trying to communicate with HTS221 sensor and read WHO_IM_I but then I always get error 17 on nrf_drv_twi_rx and receive 0 on output

Twi init

ret_code_t ret;
     const nrf_drv_twi_config_t config =
     {
        .scl = TWI_SCL_M,
        .sda = TWI_SDA_M,
        .frequency = NRF_TWI_FREQ_100K,
        .interrupt_priority = APP_IRQ_PRIORITY_HIGH
     };

     do
     {
         ret = nrf_drv_twi_init(&m_twi_master, &config, twi_handler, NULL);
         SEGGER_RTT_printf(0, " return value of twi_init %d\n", ret);
         if (NRF_SUCCESS != ret)
         {
             break;
         }
         nrf_drv_twi_enable(&m_twi_master);
     } while (0);

the below code is executed on a timer handler every 1 second

#define WHO_AM_I         0x0F
#define HTS221              0x5F

    data_I2C[0] = WHO_AM_I;
    err_code = nrf_drv_twi_tx(&m_twi_master, HTS221, data_I2C, 1, true);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_twi_rx(&m_twi_master, HTS221, check_I2C,1);
    APP_ERROR_CHECK(err_code);
    SEGGER_RTT_printf(0," data: %d  %d \n",check_I2C[0],err_code);

output : image description

 void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context) 
 {    
     switch(p_event->type) 
     { 
         case NRF_DRV_TWI_EVT_DONE: 
             // If EVT_DONE (event done) is received a device is found and responding on that particular address 
            SEGGER_RTT_printf(0,"\r\n!****************************!\r\nDevice found at 7-bit address: %#x!\r\n!****************************!\r\n\r\n", 0); 
            device_found = true; 
             break; 
        case NRF_DRV_TWI_EVT_ADDRESS_NACK: 
            SEGGER_RTT_printf(0,"No address ACK on address: %#x!\r\n", 0); 
             break; 
         case NRF_DRV_TWI_EVT_DATA_NACK: 
            SEGGER_RTT_printf(0,"No data ACK on address: %#x!\r\n", 0); 
             break; 
         default: 
             break;         
     }
Parents Reply Children
No Data
Related