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
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
}
gpio.c
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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)
main.c
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
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?