Good day all,
I am trying to build a very simple UART connection between the nrf52840 DK and my computer through a UART dongle.
First, I saw the UART example in the peripherals folder and I tested it in the Loopback mode with no problem.
When I tried to build my own example I noticed that there are 4 different UART library flavors located in different places in the SDK:
- components> libraries > serial > nrf_serial.h
- components > libraries > uart > app_uart.h
- modules > nrfx > hal > nrf_uart.h
- modules > nrfx > drivers > nrfx_uart.h
I selected nrf_uart.h (modules > nrfx > hal) just because it was used in the example.
I am confused with all the different implementations of UART library
Why are there four instead of one UART library?
Which one should I use?
Furthermore, when I run my custom example, nothing is transmitted from the Tx PIn (8) of the nRF52840 DK when I test it with the oscilloscope.
I cannot understand what I am doing wrong here. I followed the transmission steps given in the nRF52840 datasheet.
The code that I have written is given below.
#include <stdio.h> #include <stdlib.h> #include <nrf_gpio.h> //The GPIO Hardware Abstraction Layer (HAL) #include <nrf_delay.h> //For basic delaying functions #include <pca10056.h> //GPIO definitions for the nRF52840-DK (aka pca10056) #include "sdk_config.h" #include <nrf_uart.h> // UART library (modules > nrfx > hal) int main(void) { /* Configure pin 13 as standard output. */ nrf_gpio_cfg_output(BSP_LED_0); //BSP_LED_0 is pin 13 in the nRF52840-DK nrf_gpio_cfg_output(BSP_LED_1); //BSP_LED_0 is pin 13 in the nRF52840-DK nrf_gpio_pin_write(BSP_LED_0,1); // switch off the LED nrf_gpio_pin_write(BSP_LED_1,1); // switch off the LED /*Initialize the UART peripheral */ nrf_uart_baudrate_set(NRF_UART0,NRF_UART_BAUDRATE_115200); // set the baudrate nrf_uart_configure(NRF_UART0, NRF_UART_PARITY_EXCLUDED, NRF_UART_HWFC_DISABLED); // set flowcontrol and parity bit nrf_uart_txrx_pins_set(NRF_UART0, 6, 8); // set the Tx and Rx pins on nrf52840 DK nrf_uart_enable(NRF_UART0); // Enable UART nrf_uart_task_trigger(NRF_UART0, NRF_UART0->TASKS_STARTTX); // Start UART Transmission nrf_gpio_pin_write(BSP_LED_0,0); // blink once to indicate start nrf_delay_ms(1000); nrf_gpio_pin_write(BSP_LED_0,1); while (true){ nrf_uart_txd_set(NRF_UART0,0xAA); // send data to UART while(nrf_uart_event_check(NRF_UART0, NRF_UART0->EVENTS_TXDRDY) == 0){ //blink until data has been sent nrf_gpio_pin_write(BSP_LED_0,0); nrf_delay_ms(100); nrf_gpio_pin_write(BSP_LED_0,1); nrf_delay_ms(100); } } }
Thank you for your time