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

TWI, Always get ANACK error?

Hi, when trying to read a register from a chip using the IIC interface,blocking mode:

uint32_t ms5837_cmd_read(uint8_t *data, uint8_t length, uint8_t register_address)
{
uint32_t err_code;
err_code = nrf_drv_twi_tx(&m_twi_ms_5837, MS5837_TWI_ADDR, &register_address ,  1, true);



if (NRF_SUCCESS == err_code)
	
   err_code = nrf_drv_twi_rx(&m_twi_ms_5837, MS5837_TWI_ADDR, data, length, false);
		
	
APP_ERROR_CHECK(err_code);
	return err_code;	
}			

I always get the "enternal error", 0x03.

I looked up the register and found this:

image description

As you can see, there is an ANACK error, suggesting there isn't an ACK after address write.

What should I do to solve this???

Help!!!!

@endnode can you please provide a little insight?

Parents
  • As described in the nRF51 Reference manual, yes you have to trigger the stop task to generate the NACK and STOP condition:

    "The TWI master read sequence is stopped by triggering the STOP task. This task must be triggered before the last byte is extracted from RXD to ensure that the TWI master sends a NACK back to the slave before generating the stop condition."

    You trigger the task by writing 1 to it. In the TWI HAL implementation in our SDK we write 0x1UL (check out nrf_twi_task_trigger in nrf_twi.h).

Reply
  • As described in the nRF51 Reference manual, yes you have to trigger the stop task to generate the NACK and STOP condition:

    "The TWI master read sequence is stopped by triggering the STOP task. This task must be triggered before the last byte is extracted from RXD to ensure that the TWI master sends a NACK back to the slave before generating the stop condition."

    You trigger the task by writing 1 to it. In the TWI HAL implementation in our SDK we write 0x1UL (check out nrf_twi_task_trigger in nrf_twi.h).

Children
No Data
Related