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

IIC forzen

When debugging IIC, it always crashes here. what is the problem。

nrfx_twim.c,line 441.

else
{
while (!nrf_twim_event_check(p_twim, evt_to_wait))//forzen here
{
if (nrf_twim_event_check(p_twim, NRF_TWIM_EVENT_ERROR))
{
NRFX_LOG_DEBUG("TWIM: Event: %s.", EVT_TO_STR_TWIM(NRF_TWIM_EVENT_ERROR));
nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_ERROR);
nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_RESUME);
nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_STOP);
evt_to_wait = NRF_TWIM_EVENT_STOPPED;
}
}

  • The mode I set is blocking。

       ret_code_t err_code;
    
        const nrf_drv_twi_config_t twi_config = {
           .scl                = TWI_SCL2,  //
           .sda                = TWI_SDA2,  //
           .frequency          = NRF_DRV_TWI_FREQ_400K, //
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH, 
           .clear_bus_init     = false//
        };
        err_code = nrf_drv_twi_init(&m_twi0, &twi_config, NULL, NULL);
        APP_ERROR_CHECK(err_code);
        nrf_drv_twi_enable(&m_twi0);
    
    uint8_t touch_i2c_read(uint8_t Address)
    {
    	ret_code_t ret;	  
    	uint8_t destination;
    	do
        {
           ret = nrf_drv_twi_tx(&m_twi0, TOUCH_ADDR, &Address, 1, true);
     
    	   if (NRF_SUCCESS != ret)
           {
               break;
           }
    	   
           ret = nrf_drv_twi_rx(&m_twi0, TOUCH_ADDR, &destination, 1);
    	   
        }while (0);
    	
    	return destination;
    }
    
    void touch_i2c_write(uint8_t Address,uint8_t Data)
    {
    	uint8_t buffer[2];	
    
    	do
    	{
    		memset(buffer,0x00,2);
    		
    		buffer[0] = Address;
    
    		buffer[1] = Data;
    
    		nrf_drv_twi_tx(&m_twi0, TOUCH_ADDR, buffer, 2, false);
    
    	}while (0);
    }

  • Hi,

    It is hard to say exactly what is causing this, but often it is related to the pins being used by other peripherals or similar.

    Can you check what is happening on the TWI bus with a logic analyzer?

    Which GPIOs are you using for SCL and SDA?

    Best regards,
    Jørgen

  • #define TWI_SDA2                			22   //touch/eeprom/oled Master SDA pin
    #define TWI_SCL2                			23   //touch/eeprom/oled Master SCL pin
    
    #define TWI_SCL1                			16   //IC/8563 Master SCL pin
    #define TWI_SDA1                			17   //IC/8563 Master SDA pin
    
    void bsp_iic1_master_init(void)
    {
    	ret_code_t ret;
    
    	uint32_t *twim1_power = (uint32_t *)(NRF_TWIM0_BASE+0xFFC);
    
    	*twim1_power = 0;	//turn off TWIM0
    
    	*(volatile uint32_t *)twim1_power;	  //wait for register to be written (CPU runs faster than the peripherals)
    
    	*twim1_power = 1;	//turn on TWIM0
    	
    	const nrf_drv_twi_config_t config =
    	{
    	   .scl 			   = TWI_SCL1,
    	   .sda 			   = TWI_SDA1,
    	   .frequency		   = NRF_TWI_FREQ_100K,
    	   .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
    	   .clear_bus_init	   = true,
    	};
    
    	ret = nrf_drv_twi_init(&m_twi_master1, &config, NULL, NULL);
    
    	if (NRF_SUCCESS == ret)
    	{
    		nrf_drv_twi_enable(&m_twi_master1);
    	}
    	else
    	{
    		APP_ERROR_CHECK(ret);
    	}
    	
    }
    
    void bsp_iic2_master_init(void)
    {
    	ret_code_t ret;
    
    	uint32_t *twim2_power = (uint32_t *)(NRF_TWIM1_BASE+0xFFC);
    
    	*twim2_power = 0;	//turn off TWIM0
    
    	*(volatile uint32_t *)twim2_power;	  //wait for register to be written (CPU runs faster than the peripherals)
    
    	*twim2_power = 1;	//turn on TWIM0
    	
    	const nrf_drv_twi_config_t config =
    	{
    	   .scl 			   = TWI_SCL2,
    	   .sda 			   = TWI_SDA2,
    	   .frequency		   = NRF_TWI_FREQ_100K,
    	   .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
    	   .clear_bus_init	   = true,
    	};
    
    	ret = nrf_drv_twi_init(&m_twi_master2, &config, NULL, NULL);
    
    	if (NRF_SUCCESS == ret)
    	{
    		nrf_drv_twi_enable(&m_twi_master2);
    	}
    	else
    	{
    		APP_ERROR_CHECK(ret);
    	}
    	
    }
    

  • Especially when the rate is 400K, the phenomenon of endless loops is easy to occur, and the rate of 100K is relatively small. Two or three slaves are hung on each IIC bus.

  • Are you testing this on a nRF52 DK, or on a custom board? On our DK, GPIO P0.16 and P0.17 are used for LEDs and Buttons, they may not be usable for other purposes. It sounds like not all transfers lead to this condition, how often does it happen? Is the scope screen from when the issue occurs?

Related