/* www.MicroDigitalEd.com * p4_1.c UART0 transmit * * Sending string "YES" to UART0 on MSP432 LaunchPad. * The UART0 is connected to XDS110 on the LaunchPad and it has * a virtual connection to the host PC COM port. * Use TeraTerm to see the message "YES" on a PC. * * By default the subsystem master clock is 3 MHz. * Setting EUSCI_A0->BRW=26 with oversampling disabled yields 115200 Baud. * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0. */ #include "msp.h" void UART0_init(void); void delayMs(int n); int main(void) { UART0_init(); while (1) { while(!(EUSCI_A0->IFG & 0x02)) { } /* wait for transmit buffer empty */ EUSCI_A0->TXBUF = 'Y'; /* send a char */ while(!(EUSCI_A0->IFG & 0x02)) { } EUSCI_A0->TXBUF = 'e'; /* send a char */ while(!(EUSCI_A0->IFG & 0x02)) { } EUSCI_A0->TXBUF = 's'; /* send a char */ delayMs(2); /* leave a gap between messages */ } } void UART0_init(void) { EUSCI_A0->CTLW0 |= 1; /* put in reset mode for config */ EUSCI_A0->MCTLW = 0; /* disable oversampling */ EUSCI_A0->CTLW0 = 0x0081; /* 1 stop bit, no parity, SMCLK, 8-bit data */ EUSCI_A0->BRW = 26; /* 3,000,000 / 115200 = 26 */ P1->SEL0 |= 0x0C; /* P1.3, P1.2 for UART */ P1->SEL1 &= ~0x0C; EUSCI_A0->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 = 250; i > 0; i--); /* Delay */ }