Advertisement
Guest User

SimpleLink MSP432 - eUSCI - UART Mode

a guest
Apr 9th, 2020
1,149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. /* Program information:
  2.  * UART connection    : UART2 -> P3.2 (RXD) and P3.3 (TXD)
  3.  * UART system clock  : 3 MHz
  4.  * UART Baud rate     : 115200
  5.  * UART oversampling  : Enabled
  6.  * BRCLK source       : SMCLK
  7.  * UART specification : 1 stop bit, No parity, 8-bit data
  8.  *
  9. */
  10.  
  11. #include "msp.h"
  12. #include <stdint.h>
  13.  
  14. void UART2_init(void);
  15.  
  16. int main(void) {
  17. UART2_init();
  18. ...
  19. }
  20.  
  21. void UART2_init(void)
  22. {
  23.     EUSCI_A2->CTLW0 |= 1;       // UCSWRST = 1, UART on reset mode
  24.    
  25.     EUSCI_A2->BRW = 26;         // 3,000,000/115200 = 26 (N = Required division factor)
  26.     EUSCI_A2->MCTLW = 1;        // Because N > 16 so UCOS16 = 1 / Enable oversampling
  27.     EUSCI_A2->CTLW0 = 0x0081;   // 1 stop bit, no parity, SMCLK, 8-bit data  
  28.    
  29.     P3->SEL0 |= 0x0C;           // Configure P3.2(RXD) and P3.3(TXD) as UART port
  30.     P3->SEL1 &= ~0x0C;
  31.    
  32.     EUSCI_A2->CTLW0 &= ~1;      // UCSWRST = 0, UART out of reset mode
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement