I would like to use the UART at the lowest possible level and Ihave created a very simple example which uses the UART bus with the registers. The example should write word "hello" once a second to the UART, which has been set to pins 11 and 12. However, it seems that the pins remain at low all the time. I am using SES, nRF5 (16.0.0) and nRF52-DK without any additions or modifications.
I am using the leds of the board to debug the issue. I can see that leds 1-3 are on, which should mean that the registers have been set and the UART has been enabled. Led 4 flashes about once a second which should mean that the word is written to the UART and the ready event has happened as expected. However, the logic analyzer proves that nothing is written and the pins remain low at all the times.
Do you have any idea what might be wrong? The register map of the UART is very limited and therefore I did not expect any remarkable problems. Apparently I am missing something.
#include <stdint.h> #include <string.h> #include "nrf_delay.h" #include "nrf.h" #include "nrf_gpio.h" #define GPIO_PIN_17 17 #define GPIO_PIN_18 18 #define GPIO_PIN_19 19 #define GPIO_PIN_20 20 #define LED_ON 0 #define LED_OFF 1 int main (void) { char test_string [] = "Hello"; uint8_t n; nrf_gpio_range_cfg_output(17,20); // Leds nrf_gpio_cfg_output(11); // UART TX nrf_gpio_pin_write(GPIO_PIN_17, LED_OFF); nrf_gpio_pin_write(GPIO_PIN_18, LED_OFF); nrf_gpio_pin_write(GPIO_PIN_19, LED_OFF); nrf_gpio_pin_write(GPIO_PIN_20, LED_OFF); nrf_gpio_pin_write(GPIO_PIN_17, LED_ON); NRF_UART0->BAUDRATE = 0x00275000; // 9,600 bps NRF_UART0->CONFIG = 0x00000000; // Hardware flow control disabled // Parity bit disabled NRF_UART0->PSELRTS = 0xFFFFFFFF; // Disconnected NRF_UART0->PSELCTS = 0xFFFFFFFF; // Disconnected NRF_UART0->PSELTXD = 0x00000800; // Pin 11 NRF_UART0->PSELRXD = 0x00001000; // Pin 12 NRF_UART0->PSELTXD = 0xFFFFF7FF; // Pin 11 NRF_UART0->PSELRXD = 0xFFFFEFFF; // Pin 12 NRF_UART0->ENABLE = 0x00000004; // Enable nrf_gpio_pin_write(GPIO_PIN_18, LED_ON); NRF_UART0->TASKS_STARTTX = 1; // Start TX nrf_gpio_pin_write(GPIO_PIN_19, LED_ON); while (1) { for (n = 0;n < strlen(test_string);n++) { NRF_UART0->TXD = test_string[n]; // Write to the TX register while (NRF_UART0->EVENTS_TXDRDY == 0) { } // Wait until the byte has been sent NRF_UART0->EVENTS_TXDRDY = 0; } nrf_gpio_pin_write(GPIO_PIN_20, LED_ON); nrf_delay_ms(500); nrf_gpio_pin_write(GPIO_PIN_20, LED_OFF); nrf_delay_ms(500); } NRF_UART0->TASKS_STOPTX = 0; // Stop TX }