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;
}
}

Parents
  • 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);
    }

Reply
  • 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);
    }

Children
No Data
Related