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

Application firmware hangs up in twi_wait() function

Hello

I`m using the NORDIC nrf_drv_twi driver implementation from the PACK environment (version equivalent to SDK 8.1.0). Together with the S120 softdevice. If there is an active ble connection, somtimes the firmware hangs up in the twi_wait() function.

void twi_wait(void){
	do
	{
			__WFE();
	}while(m_xfer_done == false);}

Is there any known issue about priority problems or something like this, that could cause such a behaviour? The twi driver runs on APP_IRQ_PRIORITY_HIGH. If I set this priority to APP_IRQ_PRIORITY_LOW, the twi implementation completly wont work, if there is an active BLE connection. So I try to read out some data from the device via ble. This doesn`t even work, if the priority is set to LOW. If the priority is set to HIGH, it works, but sometimes the firmware hangs up in the twi_wait function. Any ideas?

Regards, BTprogrammer

  • Do you have some traces from a logic analyzer?

    I believe you have multiple error conditions here which you are not handling gracefully in your application code:

    • A twi slave might NACK the transaction if it's not ready, this will cause a twi error. Add a delay and try again.

    • A twi sensor can delay an twi transaction by "clock stretching" if it's not ready. This might cause the transaction to be busy or not complete if you call a new transaction before the previous transaction is complete. Make sure not not call a new twi transaction before the previous is finished.

    • The execution of a twi transacation might be delayed by other processes. This should not be a problem, just add a delay and try again.

    • The driver does not make a copy of the supplied parameters internally, so if you update any of the buffers before the previous twi transaction is complete, this might not work well. Make sure not to update any of the buffers before the previous transacation is complete.

    All the above can cause a problem if the application does not differentiate the different error conditions that might occur. Also check the datasheet of the twi slave on timing details that might apply.

    During debugging it might also make sense to update the driver to the latest version for possible bug fixes that might apply.

Related