-
Notifications
You must be signed in to change notification settings - Fork 4
/
uart.c
60 lines (44 loc) · 1.57 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
59
60
// Nathan Zimmerman
// Hardware_UART
// 1/7/12
// Based on Nathan Zimmerman's code at http://www.43oh.com/forum/viewtopic.php?f=10&p=15345#p15345
// Adapted by Lars Roland
//#include <msp430g2553.h>
#include <msp430.h>
#include "uart.h"
void uartInit(void)
{
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;
////////////////USCI setup////////////////
P1SEL = BIT1 + BIT2; // Set P1.1 to RXD and P1.2 to TXD
P1SEL2 = BIT1 + BIT2; //
UCA0CTL1 |= UCSSEL_2; // Have USCI use SMCLK AKA 1MHz main CLK
UCA0BR0 = 104; // Baud: 9600, N= CLK/Baud, N= 10^6 / 9600
UCA0BR1 = 0; // Set upper half of baud select to 0
UCA0MCTL = UCBRS_1; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // Start USCI
}
void uart_putc(unsigned char c)
{
UCA0TXBUF = c; // write c to TX buffer
while(!(IFG2&UCA0TXIFG));
return;
}
void uart_puts(unsigned char *tx_message)
{
unsigned int i=0; //Define end of string loop int
unsigned char *message; // message variable
unsigned int message_num; // define ascii int version variable
message = tx_message; // move tx_message into message
while(1)
{
if(message[i]==0) // If end of input string is reached, break loop.
{
break;
}
message_num = (int)message[i]; //Cast string char into a int variable
UCA0TXBUF = message_num; // write INT to TX buffer
while(!(IFG2&UCA0TXIFG));
}
}