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

Parents
  • Hi, I can't find any examples out of the box with both BLE and TWI at the moment. I think what would help here is if you have access to a logic analyzer so you can see what occurs on the serial interface. Also it might help to debug the events in twi_handler() for NRF_DRV_TWI_RX_DONE, NRF_DRV_TWI_TX_DONE, and NRF_DRV_TWI_ERROR. You should ensure that application interrupt priorities is set according to the softdevice specification document.

    FYI: We are no longer maintaining pack, so you should download the latest nRF5 SDK in zip format.

  • Hello Kenneth, I tried it that way:

    do
    {
    	res = nrf_drv_twi_tx(&m_twi_eeprom, EEPROM_HW_ADDR, m_address, 2, true);
    	if(res == NRF_SUCCESS) break;
    }while(res != NRF_SUCCESS);
    

    But than, the operation will hang up again in that while loop. This while loop will never be done, because res will not become NRF_SUCCESS anymore. I have an idea why that my happens. I will attach a sketch in another answer. Unfortunately it is not possible to add images to a comment. Is it possible that there is a problem, if two processes (application and softdevice-process are using the TWI BUS). I will try to implement some kind of a MUTEX for that behavior. But this will be very complicated, because the "normal" application process can be interrupted by an BLE event anytime. And I have no idea how it is possible, to wait for the completion of an TWI operation that is running in the normal application process. I hope the sketch and my explanation is clear enough, to understand the problem. Regards

Reply
  • Hello Kenneth, I tried it that way:

    do
    {
    	res = nrf_drv_twi_tx(&m_twi_eeprom, EEPROM_HW_ADDR, m_address, 2, true);
    	if(res == NRF_SUCCESS) break;
    }while(res != NRF_SUCCESS);
    

    But than, the operation will hang up again in that while loop. This while loop will never be done, because res will not become NRF_SUCCESS anymore. I have an idea why that my happens. I will attach a sketch in another answer. Unfortunately it is not possible to add images to a comment. Is it possible that there is a problem, if two processes (application and softdevice-process are using the TWI BUS). I will try to implement some kind of a MUTEX for that behavior. But this will be very complicated, because the "normal" application process can be interrupted by an BLE event anytime. And I have no idea how it is possible, to wait for the completion of an TWI operation that is running in the normal application process. I hope the sketch and my explanation is clear enough, to understand the problem. Regards

Children
No Data
Related