-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo_uart.c
54 lines (42 loc) · 1 KB
/
demo_uart.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//#include <stdio.h>
//#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include "nrf_gpio.h"
#include "delay.h"
#include "uart.h"
/*
* RS-232 serial port (UART)
*/
#define PIN_UART_TXD 20
#define PIN_UART_RXD 18
void uart_setup()
{
uart_disable();
// configure transmission
nrf_gpio_pin_dir_set(PIN_UART_TXD, NRF_GPIO_PIN_DIR_OUTPUT);
uart_select_pin_as_TXD(PIN_UART_TXD);
uart_select_pin_as_RTS(UART_PIN_DISABLE);
uart_select_pin_as_CTS(UART_PIN_DISABLE);
uart_set_baud(UART_BAUD_9600);
uart_set_parity_exclude();
uart_flow_control_enable();
// configure reception
uart_select_pin_as_RXD(PIN_UART_RXD);
uart_interrupt_upon_RXDRDY_enable();
uart_interrupt_upon_RXTO_enable();
uart_interrupt_upon_ERROR_enable();
uart_start_receiver();
uart_enable();
}
int main()
{
uart_setup();
uart_send_bytes("\xD\xAnRF51822:~$ ", 14);
while (true)
{
asm("wfi");
//delay_us(1000000);
}
return 0;
}