-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuart.c
58 lines (49 loc) · 1.65 KB
/
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
55
56
57
58
#include "uart.h"
void uart_init_GPIO(uint8_t port, uint16_t pin_tx, uint16_t pin_rx, uint8_t function)
{
/* Configure UART pins */
GPIO_setAsPeripheralModuleFunctionInputPin(port, pin_tx, function);
GPIO_setAsPeripheralModuleFunctionInputPin(port, pin_rx, function);
}
void uart_init()
{
/* Configure UART
* SMCLK = 16MHz, Baudrate = 115200
* http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html
*/
EUSCI_A_UART_initParam param = {0};
param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
param.clockPrescalar = 8;
param.firstModReg = 10;
param.secondModReg = 247;
param.parity = EUSCI_A_UART_NO_PARITY;
param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
param.uartMode = EUSCI_A_UART_MODE;
param.overSampling = EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;
if (STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A1_BASE, ¶m)) {
return;
}
/* Enable USCI_A0 RX interrupt */
EUSCI_A_UART_enable(EUSCI_A1_BASE);
EUSCI_A_UART_clearInterrupt(EUSCI_A1_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);
EUSCI_A_UART_enableInterrupt(EUSCI_A1_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);
/* Enable global interrupts */
// __enable_interrupt();
}
void uart_putc(char c)
{
EUSCI_A_UART_transmitData(EUSCI_A1_BASE, c);
}
void uart_puts(char *s, uint32_t len)
{
int i = 0;
for (i = 0; i < len; i++)
{
EUSCI_A_UART_transmitData(EUSCI_A1_BASE, s[i]);
}
}
char uart_getc()
{
return EUSCI_A_UART_receiveData(EUSCI_A1_BASE);
}