/* UART0-UART1 pass-through for ESP8266 Console * * ESP8266 socket header is connected to UART1. * Pin 2 - Tx (P3.3) * Pin 3 - Rx (P3.2) * UART0 is connected to the virtual COM port. * Both UART0 and UART2 are configured for 115200 Baud 8-N-1. * Use a terminal emulator to talk to UART0 through the virtual COM port. * If everything works out, type "AT" at the terminal emulator * should get "OK" back from ESP8266. * * The ESP8266 module must have the "AT" firmware. ESP8266 may have * different Baud rate than 115200 used in this program. * * Built and tested with MSP432P401R Rev. C, Keil MDK-ARM v5.24a and MSP432P4xx_DFP v3.1.0 */ #include "msp.h" void UART2init(void); void UART2Tx(char c); unsigned char UART2Rx(void); void UART0init(void); void UART0Tx(char c); unsigned char UART0Rx(void); void delayMs(int n); int main(void) { char c; UART2init(); UART0init(); delayMs(1); /* wait for output line to stabilize */ UART0Tx('>'); /* send prompt */ for(;;) { c = UART0Rx(); if (c != 0) UART2Tx(c); c = UART2Rx(); if (c != 0) UART0Tx(c); } } void UART2init(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; /* 3000000 / 115200 = 26 */ P3->SEL0 |= 0x0C; /* P3.3, P3.2 for UART2 */ P3->SEL1 &= ~0x0C; EUSCI_A2->CTLW0 &= ~1; /* take UART out of reset mode */ } void UART2Tx(char c) { while(!(EUSCI_A2->IFG & 0x02)) { } /* wait for transmit buffer empty */ EUSCI_A2->TXBUF = c; /* send a char */ } unsigned char UART2Rx(void){ char c; if ((EUSCI_A2->IFG & 0x01) == 0) /* if Rx buffer is empty */ return 0; c = EUSCI_A2->RXBUF; /* read the receive char */ return c; } void UART0init(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; /* 3000000 / 115200 = 26 */ P1->SEL0 |= 0x0C; /* P1.3, P1.2 for UART0 */ P1->SEL1 &= ~0x0C; EUSCI_A0->CTLW0 &= ~1; /* take UART out of reset mode */ } void UART0Tx(char c) { while(!(EUSCI_A0->IFG & 0x02)) { } /* wait for transmit buffer empty */ EUSCI_A0->TXBUF = c; /* send a char */ } unsigned char UART0Rx(void){ char c; if ((EUSCI_A0->IFG & 0x01) == 0) /* if Rx buffer is empty */ return 0; c = EUSCI_A0->RXBUF; /* read the receive char */ return c; } /* system clock at 3 MHz */ void delayMs(int n) { int i, j; for (j = 0; j < n; j++) for (i = 750; i > 0; i--); /* Delay */ }