/* UART0-UART1 pass-through for ESP8266 Console * * ESP8266 socket header is connected to UART1. * Pin 2 - Tx (PB1) * Pin 3 - Rx (PB0) * UART0 is connected to the virtual COM port. * Both UART0 and UART1 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 Keil MDK-ARM v5.24a and TM4C_DFP v1.1.0 */ #include #include "TM4C123.h" void UART0Tx(char c); unsigned char UART0Rx(void); void UART1Tx(char c); unsigned char UART1Rx(void); void delayMs(int n); int main(void) { char c; SYSCTL->RCGCUART |= 2; /* provide clock to UART1 */ SYSCTL->RCGCGPIO |= 2; /* enable clock to PORTB */ /* UART1 initialization */ UART1->CTL = 0; /* disable UART1 */ UART1->IBRD = 27; /* 50MHz/16=3.125MHz, 3.125MHz/115200=27.1267 */ UART1->FBRD = 8; /* fraction part, 0.1267*64=8 */ UART1->CC = 0; /* use system clock */ UART1->LCRH = 0x60; /* 8-bit, no parity, 1-stop bit, no FIFO */ UART1->CTL = 0x301; /* enable UART1, TXE, RXE */ /* UART1 TX and RX use PB1 and PB0. Set them up. */ GPIOB->DEN = 0x03; /* Make PB0 and PB1 as digital */ GPIOB->AFSEL = 0x03; /* Use PB0, PB1 alternate function */ GPIOB->PCTL = 0x11; /* configure PB0 and PB1 for UART */ SYSCTL->RCGCUART |= 1; /* provide clock to UART0 */ SYSCTL->RCGCGPIO |= 1; /* enable clock to PORTA */ /* UART0 initialization */ UART0->CTL = 0; /* disable UART0 */ UART0->IBRD = 27; /* 50MHz/16=3.125MHz, 3.125MHz/115200=27.1267 */ UART0->FBRD = 8; /* fraction part, 0.1267*64=8 */ UART0->CC = 0; /* use system clock */ UART0->LCRH = 0x60; /* 8-bit, no parity, 1-stop bit, no FIFO */ UART0->CTL = 0x301; /* enable UART0, TXE, RXE */ // UART0 TX and RX use PA0 and PA1. Set them up. GPIOA->DEN = 0x03; /* Make PA0 and PA1 as digital */ GPIOA->AFSEL = 0x03; /* Use PA0, PA1 alternate function */ GPIOA->PCTL = 0x11; /* configure PA0 and PA1 for UART */ delayMs(1); /* wait for output line to stabilize */ UART0Tx('>'); /* send prompt to console */ for(;;) { c = UART0Rx(); if (c != 0) UART1Tx(c); c = UART1Rx(); if (c != 0) UART0Tx(c); } } void UART1Tx(char c) { while((UART1->FR & 0x20) != 0); /* wait until Tx buffer not full */ UART1->DR = c; /* before giving it another byte */ } /* non-blocking read. returns 0 if no char available */ unsigned char UART1Rx(void){ char c; if ((UART1->FR & 0x10) != 0) /* if RSx buffer is empty */ return 0; /* return 0 */ c = UART1->DR; /* read the received data */ return c; /* and return it */ } void UART0Tx(char c) { while((UART0->FR & 0x20) != 0); /* wait until Tx buffer not full */ UART0->DR = c; /* before giving it another byte */ } /* non-blocking read. returns 0 if no char available */ unsigned char UART0Rx(void){ char c; if ((UART0->FR & 0x10) != 0) /* if Rx buffer is empty */ return 0; /* return 0 */ c = UART0->DR; /* read the received data */ return c; /* and return it */ } /* delay n milliseconds (50 MHz CPU clock) */ void delayMs(int n) { int i, j; for(i = 0 ; i< n; i++) for(j = 0; j < 6265; j++) {} /* do nothing for 1 ms */ }