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

UARTE1 using nrfx_uarte , only transmit 6 bytes , fails on 7th byte and transmit again, and able to read only 6 bytes in return.

Hi everyone

I have been trying to use UARTE1 + UART0 combination for a device that i am working on, I have implemented the UART0 using the nrfx_uart library and it works fine

Problem : 

1. nrfx_uarte peripheral gives me error interrupt on 7th byte and not transmit anything after that
2. only receive 6 bytes and no bytes after that , though there's data on the uart lines.

I am aware of the nrf_serial library , but that application does not suit the development that i am working on.
Can you please help me how can i get it working?

Here is the initalization i am using.

//Boolean flag to be set in interrupt handler;
static volatile bool uart_xfer_done;
//Uart instance to be used.
static const nrfx_uarte_t uart1 =
            NRFX_UARTE_INSTANCE (1); 

//uart event handler decalartion
static void  uart_event_handler(nrfx_uarte_event_t const * p_event,void * p_context);


void uart_lte_init(uint32_t rx_pin,uint32_t tx_pin,uint32_t baud_rate)
{


    nrfx_uarte_config_t nrf_uart1;
    nrf_uart1.pselrxd = rx_pin ;
    nrf_uart1.pseltxd = tx_pin;
    nrf_uart1.pselcts = NRF_UARTE_PSEL_DISCONNECTED;
    nrf_uart1.pselrts = NRF_UARTE_PSEL_DISCONNECTED;
    nrf_uart1.hwfc = NRF_UARTE_HWFC_DISABLED;
    nrf_uart1.parity = NRF_UARTE_PARITY_EXCLUDED;
    nrf_uart1.interrupt_priority = NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY;
    nrf_uart1.p_context = NULL;
   
 switch(baud_rate)
    {
         case baud_rate_lte_1200:
              nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_1200;
              break;

         case baud_rate_lte_2400:
              nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_2400;
              break;

         case baud_rate_lte_4800:
              nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_4800;
              break;

         case baud_rate_lte_9600:
              nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_9600;
              break;

         case baud_rate_lte_14400:
              nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_14400;
              break;

         case baud_rate_lte_19200:
              nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_19200;
              break;

         case baud_rate_lte_28800:
              nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_28800;
              break;

         case baud_rate_lte_31250:
              nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_31250;
              break;

         case baud_rate_lte_38400:
              nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_38400;
              break;

         case baud_rate_lte_56000:
              nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_56000;
              break;

         case baud_rate_lte_57600:
              nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_57600;
              break;

         case baud_rate_lte_76800:
              nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_76800;
              break;

         case baud_rate_lte_115200:
              nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_115200;
              break;

         default:
              break;


    }
    
    nrfx_uarte_init(&uart1,&nrf_uart1,uart_event_handler);

//enable the rx

    nrf_uarte_event_clear(uart1.p_reg, NRF_UARTE_EVENT_ERROR);
    nrf_uarte_event_clear(uart1.p_reg, NRF_UARTE_EVENT_RXDRDY);
    nrf_uarte_task_trigger(uart1.p_reg, NRF_UARTE_TASK_STARTRX);
    
    
   
}

  • Hi,

    It does not look like you set any receive buffer in your code. If you do not do this, the UARTE peripheral can only receive bytes to fill the internal HW FIFO before it will generate an OVERRUN error. You can set the buffer and the length of the buffer using the nrfx_uarte_rx() function.

    Best regards,
    Jørgen

  • I have done that in some other function where i read one byte at a time 
    Do i need to clear some register or something to receive more data
    Here's the full code

    #include "nrf_serial.h"
    #include "uart_lte.h"
    
    //Boolean flag to be set in interrupt handler;
    static volatile bool uart_xfer_done;
    //Uart instance to be used.
    static const nrfx_uarte_t uart1 =
                NRFX_UARTE_INSTANCE (1); 
    
    //uart event handler decalartion
    static void  uart_event_handler(nrfx_uarte_event_t const * p_event,void * p_context);
    
    
    /*
     * This function uses UARTE1 peripheral instance for communication
     * @param rx_pin to be used
     * @param tx_pin to be used
     * @return None
    */
    
    
    void uart_lte_init(uint32_t rx_pin,uint32_t tx_pin,uint32_t baud_rate)
    {
    
    
        nrfx_uarte_config_t nrf_uart1;
        nrf_uart1.pselrxd = rx_pin ;
        nrf_uart1.pseltxd = tx_pin;
        nrf_uart1.pselcts = NRF_UARTE_PSEL_DISCONNECTED;
        nrf_uart1.pselrts = NRF_UARTE_PSEL_DISCONNECTED;
        nrf_uart1.hwfc = NRF_UARTE_HWFC_DISABLED;
        nrf_uart1.parity = NRF_UARTE_PARITY_EXCLUDED;
        nrf_uart1.interrupt_priority = 7;
        nrf_uart1.p_context = NULL;
       
     switch(baud_rate)
        {
             case baud_rate_lte_1200:
                  nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_1200;
                  break;
    
             case baud_rate_lte_2400:
                  nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_2400;
                  break;
    
             case baud_rate_lte_4800:
                  nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_4800;
                  break;
    
             case baud_rate_lte_9600:
                  nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_9600;
                  break;
    
             case baud_rate_lte_14400:
                  nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_14400;
                  break;
    
             case baud_rate_lte_19200:
                  nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_19200;
                  break;
    
             case baud_rate_lte_28800:
                  nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_28800;
                  break;
    
             case baud_rate_lte_31250:
                  nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_31250;
                  break;
    
             case baud_rate_lte_38400:
                  nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_38400;
                  break;
    
             case baud_rate_lte_56000:
                  nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_56000;
                  break;
    
             case baud_rate_lte_57600:
                  nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_57600;
                  break;
    
             case baud_rate_lte_76800:
                  nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_76800;
                  break;
    
             case baud_rate_lte_115200:
                  nrf_uart1.baudrate = NRF_UARTE_BAUDRATE_115200;
                  break;
    
             default:
                  break;
    
    
        }
        
        nrfx_uarte_init(&uart1,&nrf_uart1,uart_event_handler);
    
    //The below lines have not been implemented by Nordic in their official library
    //This is to enable the Reception of data.
    //NOTE:DO NOT REMOVE IT EVER OR YOU ARE SCREWED , JUST LIKE THE ENVIORNMENT THESE DAYS.
    
    //NOTE:enable the rx to receive data , some bug is there , only receiving 6 bytes of data and not more.
      nrf_uarte_task_trigger(uart1.p_reg, NRF_UARTE_TASK_STARTRX);
      nrf_uarte_event_clear(uart1.p_reg, NRF_UARTE_EVENT_ERROR);
     
      nrf_uarte_task_trigger(uart1.p_reg, NRF_UARTE_TASK_STOPRX);
      nrf_uarte_event_clear(uart1.p_reg, NRF_UARTE_EVENT_RXDRDY);
    
    }
    
    
    /*
     * This function uninitalize the UARTE1
     * @param None
     * @param None
     * @return None
    */
    
    
    void uart_lte_uninit()
    {
    
        nrfx_uarte_uninit(&uart1);
    
    }
    
    /*
     * This function writes a byte of data to the UARTE1
     * @param Data byte to be sent
     * @param None
     * @return None
    */
    
    void write_byte_lte (uint8_t data)
    {
    
         uart_xfer_done=false;
         nrfx_uarte_tx(&uart1,&data,1);
         SEGGER_RTT_printf(0,"BYTE %c\r\n",data);
         while(!uart_xfer_done);
    
    
    }
    
    
    /*
     * This function reads a byte of data from UARTE1
     * @param Data byte to be sent
     * @param None
     * @return None
    */
    
    uint8_t read_byte_lte ()
    {
    
       uint8_t rx_data;
       uart_xfer_done=false;
       
       nrfx_uarte_rx(&uart1,&rx_data,1);
       SEGGER_RTT_printf(0,"BYTE %c\r\n",rx_data);
       while(!uart_xfer_done);
    
       return rx_data;
    
    }
    
    
    /**
     * @brief UART1 Event handler
     * @param event
    */
    void uart_event_handler(nrfx_uarte_event_t const * p_event,void * p_context)
    {
      
     
      switch(p_event->type)
      {
          case NRFX_UARTE_EVT_TX_DONE:
                 uart_xfer_done = true;
                 SEGGER_RTT_printf(0,"Tx lte\r\n");
                 break;
          case NRFX_UARTE_EVT_RX_DONE:
                 SEGGER_RTT_printf(0,"Rx lte\r\n");
                 uart_xfer_done = true;
                 break;
          case NRFX_UARTE_EVT_ERROR:
                 SEGGER_RTT_printf(0,"Error\r\n");
                 break;      
          default:
                 break;
      }
    
    }

  • I cannot see where you call read_byte_lte() in that code. If you do not call this fast enough to keep up with the incoming data, you may also end up in this situation. Also, it looks like you trigger the STARTRX task manually in the code after init, without setting the buffer (as far as I can see from what you have posted). The STARTRX task will also be triggered inside nrfx_uarte_rx when you set the first buffer. Can you post a full minimal project that can be used to reproduce the issue you are seeing on a DK?

Related