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

TWI Init/Uninit Driver Bug

I have an application that uses many TWI buses, on many pins of the nRF51. I handle this by initializing/uninitializing a single TWI bus for different transactions. I ran into the issue where the TWI driver would get stuck in "transfer_in_progress" every once in awhile while using SDK v9.0. When debugging I could see that the "transfer_in_progress" flag is only cleared in the interrupt, so it was impossible to recover from a stuck "transfer_in_progress" after a disable/uninit. To resolve my issue I added:

m_cb[p_instance->instance_id].transfer.transfer_in_progress = false;

to the

void nrf_drv_twi_disable(nrf_drv_twi_t const * const p_instance)

function. I am probably circumventing some terrible race condition that I have created, but with this change my tests have done thousands of successful TWI transactions. The original author of the driver might have a better idea how to prevent the failure. I dislike maintaining my own driver files because it prevents me from taking SDK updates wholesale, it would be nice to have a fix in the SDK. Maybe this has been fixed in v10.0 or v11.0?

Related