Hello,
I've been trying to write my own library that uses UART.
I went through the "uart" example and wrote this piece of code.
uart.c
void uart_set_baudrate(uint32_t val) { NRF_UART0->BAUDRATE = val; } void uart_configure(uint32_t parity, uint32_t hwfc) { NRF_UART0->CONFIG = (parity << UART_CONFIG_PARITY_Pos) | (hwfc << UART_CONFIG_HWFC_Pos); } void uart_set_pins(uint32_t txpin, uint32_t rxpin) { NRF_UART0->PSELRXD = rxpin; NRF_UART0->PSELTXD = txpin; } void uart_enable(void) { NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Enabled; } void uart_init(void) { uart_set_baudrate(UART_BAUDRATE_BAUDRATE_Baud115200); uart_configure(UART_CONFIG_PARITY_Excluded, UART_CONFIG_HWFC_Disabled); uart_set_pins(6, 8); uart_enable(); } void uart_write(uint8_t data) { NRF_UART0->TXD = data; }
gpio.c
void gpio_out_set(uint32_t pin_num) { NRF_GPIO_Type * reg = NRF_P0; reg->OUTSET = (1 << pin_num); } void gpio_config_input(uint32_t pin_num, uint32_t pull) { NRF_GPIO_Type * reg = NRF_P0; reg->PIN_CNF[pin_num] = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | ((uint32_t)pull << GPIO_PIN_CNF_PULL_Pos) | ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); // input sense options } void gpio_config_output(uint32_t pin_num) { NRF_GPIO_Type * reg = NRF_P0; reg->PIN_CNF[pin_num] = ((uint32_t)GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos) | ((uint32_t)GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) | ((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); }
main.c
gpio_out_set(6); gpio_config_output(6); gpio_config_input(8, GPIO_PIN_CNF_PULL_Disabled); uart_init(); while(true) { //send_packet_blocking(); nrf_delay_ms(100); uart_write('A'); }
I modified the example to work without DMA and I get the same values in the registers of the UART (except for the interrupts) and the GPIO.
I exported the registers after the initialization and my code setups the registers exactly the same as the example "uart"
But I don't get anything in the serial port.
Any advice?