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

nrf_drv_twi_tx() return NRF_ERROR_BUSY

Hi,

I am using the following function to read the content of a register:

static ret_code_t read_reg(uint8_t slave_address, uint8_t register_address, uint8_t *value) {
ret_code_t err_code;
err_code = nrf_drv_twi_tx(&m_twi, slave_address, &register_address, 1, true);
VERIFY_SUCCESS(err_code);

err_code = nrf_drv_twi_rx(&m_twi, slave_address, value, 1);
VERIFY_SUCCESS(err_code);

return err_code;
}

I call is this way:

#define MAX30101_ADDR					(0xAE >> 1)
#define MAX30101_REG_PART_ID			0xFFU

uint8_t part_id;
ret_code_t err_code;

err_code = read_reg(MAX30101_ADDR, MAX30101_REG_PART_ID, &part_id);
VERIFY_SUCCESS(err_code);

The problem is that this always return NRF_ERROR_BUSY

When I try to use it this way:

do {
	err_code = read_reg(MAX30101_ADDR, MAX30101_REG_PART_ID, &part_id);
} while (err_code == NRF_ERROR_BUSY);

I never exit the do-while.

What am I doing wrong ? why does it keep returning NRF_ERROR_BUSY ?

Parents
  • show us your TWI init function. If you supplied TWI handler nrf_drv_twi_X functions will become non blocking and you'll have to manually handle waiting for end of the transfer. If you fail to do so you'll get NRF_ERROR_BUSY. Solution is either to specify NULL as TWI event handler and get blocking behavior from nrf_drv_twi_X or use app_twi which will handle all this for you and allow easy mixing of blocking and non blocking calls.

Reply
  • show us your TWI init function. If you supplied TWI handler nrf_drv_twi_X functions will become non blocking and you'll have to manually handle waiting for end of the transfer. If you fail to do so you'll get NRF_ERROR_BUSY. Solution is either to specify NULL as TWI event handler and get blocking behavior from nrf_drv_twi_X or use app_twi which will handle all this for you and allow easy mixing of blocking and non blocking calls.

Children
No Data
Related