/* www.microDigitalEd.com * p4_3.c UART2 transmit * * Sending a string "Hello\r\n" to UART2 on MSP432 LaunchPad. * The UART2 is connected to P3.2 (RXD) and P3.3 (TXD) on the LaunchPad. * A 3.3V signal level to USB cable is used to connect to * the host PC COM port. * Use TeraTerm to see the message "Hello" on a PC. * * By default the subsystem master clock is 3 MHz. * Setting EUSCI_A2->BRW=26 with oversampling disabled yields 115200 Baud. * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0 * on XMS432P401R Rev C. */ #include "msp.h" void UART2_init(void); void delayMs(int n); int main(void) { char message[] = "Hello\r\n"; int i; UART2_init(); while (1) { for (i = 0; i < 7; i++) { while(!(EUSCI_A2->IFG & 0x02)) { } /* wait for transmit buffer empty */ EUSCI_A2->TXBUF = message[i]; /* send a char */ } delayMs(10); /* leave a gap between messages */ } } void UART2_init(void) { EUSCI_A2->CTLW0 |= 1; /* put in reset mode for config */ EUSCI_A2->MCTLW = 0; /* disable oversampling */ EUSCI_A2->CTLW0 = 0x0081; /* 1 stop bit, no parity, SMCLK, 8-bit data */ EUSCI_A2->BRW = 26; /* 3,000,000 / 115200 = 26 */ P3->SEL0 |= 0x0C; /* P3.3, P3.2 for UART */ P3->SEL1 &= ~0x0C; EUSCI_A2->CTLW0 &= ~1; /* take UART out of reset mode */ } /* delay milliseconds when system clock is at 3 MHz */ void delayMs(int n) { int i, j; for (j = 0; j < n; j++) for (i = 750; i > 0; i--); /* Delay */ }