Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Program information:
- * UART connection : UART2 -> P3.2 (RXD) and P3.3 (TXD)
- * UART system clock : 3 MHz
- * UART Baud rate : 115200
- * UART oversampling : Enabled
- * BRCLK source : SMCLK
- * UART specification : 1 stop bit, No parity, 8-bit data
- *
- */
- #include "msp.h"
- #include <stdint.h>
- void UART2_init(void);
- int main(void) {
- UART2_init();
- ...
- }
- void UART2_init(void)
- {
- EUSCI_A2->CTLW0 |= 1; // UCSWRST = 1, UART on reset mode
- EUSCI_A2->BRW = 26; // 3,000,000/115200 = 26 (N = Required division factor)
- EUSCI_A2->MCTLW = 1; // Because N > 16 so UCOS16 = 1 / Enable oversampling
- EUSCI_A2->CTLW0 = 0x0081; // 1 stop bit, no parity, SMCLK, 8-bit data
- P3->SEL0 |= 0x0C; // Configure P3.2(RXD) and P3.3(TXD) as UART port
- P3->SEL1 &= ~0x0C;
- EUSCI_A2->CTLW0 &= ~1; // UCSWRST = 0, UART out of reset mode
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement