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

Sequential calls to nrf_drv_twi_tx fails [SDK9]

When calling nrf_drv_twi_tx() once like in the snippet below it works, but when the function is called two or more times sequentially, it fails. However running a nrf_delay_ms() delay between the calls makes it work again.

Works

nrf_drv_twi_init(&twi, NULL, NULL); 
nrf_drv_twi_enable(&twi);
nrf_drv_twi_tx(&twi, addr, &(buf[0]), buf_size, false);

Fails

nrf_drv_twi_init(&twi, NULL, NULL); 
nrf_drv_twi_enable(&twi);
nrf_drv_twi_tx(&twi, addr, &(buf[0]), buf_size, false);
nrf_drv_twi_tx(&twi, addt, &(buf[0]), buf_size, false);

Works again

nrf_drv_twi_init(&twi, NULL, NULL); 
nrf_drv_twi_enable(&twi);
nrf_drv_twi_tx(&twi, addr, &(buf[0]), buf_size, false);
nrf_delay_ms(10);
nrf_drv_twi_tx(&twi, addt, &(buf[0]), buf_size, false);

It fails simply by running the app_error_handler. Which spits out some corrupted data over the serial interface.

Solved

The flash IC I'm using requires a 10ms wait between each write. Therefore the IC would NACK the second write if it hasn't been 10ms since the last write.

Related