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

nRF52840 UART app_uart_init

Hi I plan on using two UART modules from the nRF52840 which is why I am trying to use the app_uart_init however at this stage I keep getting the following error:

undefined reference to 'app_uart_init'

Moreover what is the difference between UARTE and UART? or would you recommend using the Serial library instead?

#include <stdbool.h>
#include <stdint.h>
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "app_uart.h"
#include "nrf_uart.h"

#define UART1_TX NRF_GPIO_PIN_MAP(1,1)
#define UART1_RX NRF_GPIO_PIN_MAP(1,2)

void uart_error_handle(app_uart_evt_t * p_event)
{

}

int main(void)
{
    /*UART*/
    const app_uart_comm_params_t comm_params =
      {
          UART1_RX,
          UART1_TX,
          APP_UART_FLOW_CONTROL_DISABLED,
          false,
          NRF_UART_BAUDRATE_9600
      };
    
    uint8_t UART1_RX_BUF;
    uint8_t UART1_TX_BUF;

    const app_uart_buffers_t p_buffers = 
      {
          UART1_RX_BUF,
          255,
          UART1_TX_BUF,
          255
      };

    app_uart_init (&comm_params,&p_buffers,uart_error_handle,APP_IRQ_PRIORITY_LOWEST);    

}

Parents
  • Hi!

    What IDE are you using? You need to add the path to app_uart.h in your project, where the function is defined, so that the compiler can find it. It should be in SDK/components/libraries/uart.

     

    Moreover what is the difference between UARTE and UART?

    The nRF52 series has two UART peripherals, legacy peripherals (UART) and peripherals using EasyDMA (UARTE), which is a direct memory access module used to gain direct access to Data RAM. 


    or would you recommend using the Serial library instead?

    The advantages of the Serial port library over UART library is described in the documentation:

    This module allows to create and handle serial port instances. It is designed as a more sophisticated replacement for the app_uart module. The following are the advantages of this module over app_uart:

    • API is more generic and robust: you can read or write any amount of bytes.
    • Multi-instance capability.
    • The module can work in three modes: POLLING, IRQ, and DMA.
    • Calls can be asynchronous and synchronus (with timeouts).
    • Independent RX/TX FIFOs with configurable sizes.
    • Configurable RX/TX transfer buffers (smallest transfer slice).
    • Event handler (not mandatory).
    • Sleep handler (not mandatory).

    You can find an example of how to use the Serial library in the SDK. 

    Best regards,

    Heidi

Reply
  • Hi!

    What IDE are you using? You need to add the path to app_uart.h in your project, where the function is defined, so that the compiler can find it. It should be in SDK/components/libraries/uart.

     

    Moreover what is the difference between UARTE and UART?

    The nRF52 series has two UART peripherals, legacy peripherals (UART) and peripherals using EasyDMA (UARTE), which is a direct memory access module used to gain direct access to Data RAM. 


    or would you recommend using the Serial library instead?

    The advantages of the Serial port library over UART library is described in the documentation:

    This module allows to create and handle serial port instances. It is designed as a more sophisticated replacement for the app_uart module. The following are the advantages of this module over app_uart:

    • API is more generic and robust: you can read or write any amount of bytes.
    • Multi-instance capability.
    • The module can work in three modes: POLLING, IRQ, and DMA.
    • Calls can be asynchronous and synchronus (with timeouts).
    • Independent RX/TX FIFOs with configurable sizes.
    • Configurable RX/TX transfer buffers (smallest transfer slice).
    • Event handler (not mandatory).
    • Sleep handler (not mandatory).

    You can find an example of how to use the Serial library in the SDK. 

    Best regards,

    Heidi

Children
  • Hi Heidi,

    Thank you for getting back to me!

    I am using Segger, as far as I know I added that path but I will check again.

    In which cases would you suggest using EasyDMA (UARTE) ? Apart from accessing the read/write data buffers in UART, what added benefits does it provide?

    Br

    Luke

  • Hi, in most cases, I would suggest using UARTE. 

    Taken from the PS of the nRF52840, the main features of UARTE

    • Full-duplex operation
    • Automatic hardware flow control
    • Optional even parity bit checking and generation
    • EasyDMA
    • Up to 1 Mbps baudrate
    • Return to IDLE between transactions supported (when using HW flow control)
    • One or two stop bit
    • Least significant bit (LSB) first

    while the main feature of UART are

    • Full-duplex operation
    • Automatic hardware flow control
    • Parity checking and generation for the 9th data bit

    However, the power consumption when using UARTE is generally much higher. 

    Best regards,

    Heidi

  • both UART and UARTE have huge disadvantage - it's unable to use polling mode. Look at the piece of code of nrfx_uarte_rx function:

    ....

    do {
        endrx  = nrf_uarte_event_check(p_instance->p_reg, NRF_UARTE_EVENT_ENDRX);
        rxto   = nrf_uarte_event_check(p_instance->p_reg, NRF_UARTE_EVENT_RXTO);
        error  = nrf_uarte_event_check(p_instance->p_reg, NRF_UARTE_EVENT_ERROR);            
    } while ((!endrx) && (!rxto) && (!error));

    ...

    Its endless loop if there is no incoming data. Who write code like this??

Related