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

TWIM XFER ERROR

Hi, i am using:

-nRF 52 DK

-nRF 52832

-Sensor of Maxim Integrated

-SDK 17.0.2

I have some problems in handling the I2C through the nrfx module.

This is my ReadByte function and the handler:


 static const nrfx_twim_t twim_instance = NRFX_TWIM_INSTANCE(0);
 volatile bool twim_tx_done = false;
 volatile bool twim_rx_done = false;


void twim_handler(nrfx_twim_evt_t const * p_event, void * p_context)
{

    size_t primaryBufferSize = p_event->xfer_desc.primary_length;
    uint8_t *bytesTransferred = p_event->xfer_desc.p_primary_buf;
    size_t secondaryBufferSize = p_event->xfer_desc.secondary_length;
    uint8_t *bytesRead = p_event->xfer_desc.p_secondary_buf;

    switch (p_event->type)
    {
        case NRFX_TWIM_EVT_DONE:
    
            NRF_LOG_INFO("STATE OF BUFFERS IN EVENT HANDLER:");
            NRF_LOG_INFO("\t Size of primary buffer: %d", primaryBufferSize);
            NRF_LOG_INFO("\t Size of secondary buffer: %d", secondaryBufferSize);
          
					if (p_event->xfer_desc.type == NRFX_TWIM_XFER_TX)
            {
                twim_tx_done = true;
            }
          
						if (p_event->xfer_desc.type == NRFX_TWIM_XFER_RX)
            {
                twim_rx_done = true;
            }
            break;
        
				case NRFX_TWIM_EVT_ADDRESS_NACK:
            NRF_LOG_INFO("Received NACK after sending address!");
            break;
        
				case NRFX_TWIM_EVT_DATA_NACK:
            NRF_LOG_INFO("Received NACK after sending data.");
            break;
        default:
            break;
    }
    
    
uint8_t readByte( uint8_t familyByte, uint8_t indexByte)
{

		nrfx_err_t err_code;

		uint8_t StatusByte;    
    uint8_t ReturnByte;
   
    uint8_t rx_buffer[2];
		size_t rx_lenght =2;

		uint8_t tx_buffer[] = {familyByte, indexByte};    
		size_t tx_lenght = sizeof(familyByte) + sizeof(indexByte);

		nrfx_twim_xfer_desc_t tx_xfer = NRFX_TWIM_XFER_DESC_TX(address, tx_buffer, tx_lenght);
		err_code = nrfx_twim_xfer(&twim_instance, &tx_xfer, 0);
		APP_ERROR_CHECK(err_code);
			
       while (!twim_tx_done)
        {
            __WFE();
        } 
        twim_tx_done  = false;
  
		
		nrfx_twim_xfer_desc_t rx_xfer = NRFX_TWIM_XFER_DESC_RX(address, rx_buffer, rx_lenght);
		err_code = nrfx_twim_xfer(&twim_instance, &rx_xfer, 0);
		APP_ERROR_CHECK(err_code);
	
		
         while (!twim_rx_done )
        {
            __WFE();
        } 
        twim_rx_done  = false;
  
		StatusByte = rx_buffer[0];
         NRF_LOG_INFO("Status Byte: %lu \n",StatusByte);
    
		ReturnByte = rx_buffer[1];  
		return ReturnByte;
}

    
    

	}

I am stack at the "nrfx_twim_xfer" function where i am getting this EVENT_ERROR checked in the TWIM0 viewer in debug mode, the ERRORSRC is 0x02 (ANACK).:

I was not able to retrieve information about this on the blog. 

Have you an idea why this happen and i why i am not able to let my TWIM function work?

Thanks,

polimarte

Related