Hi NXP,
I'm using the LPC865M201JHI48 microcontroller for UART communication. The transmit function works correctly (I verified this using a serial terminal like PuTTY), but the receive function is not working properly.
What I'm working on:
I'm trying to interface the ESP8266 Wi-Fi module with my LPC865M201JHI48 controller. When I send the "AT" command to the Wi-Fi module over UART, I expect to receive an "OK" response from the module. However, instead of receiving "OK", I'm continuously getting the character 'A'.
Note:
The ESP8266's blue LED is blinking during this process, which indicates that the module is transmitting data (TX activity). This confirms that the ESP8266 is responding, but my microcontroller is not receiving the data correctly.
pin connection
ESP8266 Pin Connect to LPC865
VCC | 3.3V |
GND | GND |
TX | RX of LPC (UART0_RX - PIO0_31) |
RX | TX of LPC (UART0_TX - PIO1_9) |
CH_PD (EN) | Pull HIGH (3.3V) |
RST | Pull HIGH (3.3V) |
char response[128];
/*void UART0_SendChar(char c) {
while (!(USART0->STAT & (1 << 2)));
USART0->TXDAT = c;
}
void UART0_SendString(const char *str) {
while (*str) UART0_SendChar(*str++);
}
void send_AT(const char *cmd, uint32_t delay_time) {
UART0_SendString(cmd);
// UART0_SendString("\r\n");
delay_ms(delay_time);
}
void UART0_ReceiveFullResponse(char *response, int max_len)
{
int i = 0;
char c;
uint32_t timeout;
int newline_count = 0;
while (i < (max_len - 1))
{
timeout = 200000;
while (!(USART0->STAT & USART_STAT_RXRDY_MASK) && --timeout);
if (timeout == 0) break;
c = USART0->RXDAT;
response[i++] = c;
// Optional: Count newlines to wait for complete response
if (c == '\n' || c == '\r') {
newline_count++;
if (newline_count >= 2) break; // Assume full response after 2 line breaks
}
}
response[i] = '\0';
}
char LPUART0_receive_char(void)
{ /* Function to Receive single Char */
char receive;
while((USART0 ->STAT & USART_STAT_RXRDY_MASK)>>USART_STAT_RXRDY_SHIFT==0);
/* Wait for received buffer to be full */
receive= USART0->RXDAT; /* Read received data*/
return receive;
}
// === MAIN ===
int main(void)
{
usart_config_t config;
// === Init ===
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
CLOCK_Select(kUART0_Clk_From_MainClk);
USART_GetDefaultConfig(&config);
config.enableRx = true;
config.enableTx = true;
config.baudRate_Bps = BOARD_DEBUG_USART_BAUDRATE;
// USART_Init(USART0, &config, CLOCK_GetFreq(kCLOCK_MainClk));
USART_Init(EXAMPLE_USART, &config, EXAMPLE_USART_CLK_FREQ);
delay_ms(2000);
// Init system modules
main_init();
init_key();
spi_init();
tft_init();
//wifi pins
GPIO->DIR[0] |=(1<<24); // PIO0_24-->Enable
GPIO->DIR[0] |=(1<<13); // PIO0_13-->Reset
GPIO->SET[0] |=(1<<24); //En set
// To reset ESP8266
GPIO->CLR[0] |= (1 << 13); // Assume PIO0_13 connected to RST
delay_ms(100); // Hold low
GPIO->SET[0] |= (1 << 13); // Pull high again
fan_off();
buzzer_off();
boot_screen();
heater_off();
idel_mode_flag = ON;
current_mode = 0;
boot_done_flag = 1;
while (1)
{
send_AT("AT\n\r", 1000); // Send command
UART0_ReceiveFullResponse(response, sizeof(response));
displayText12x8(10, 10, response, YELLOW_COLOR, BLACK_COLOR); // Or print to UART for debugging
delay_ms(500);
display_clr(BLACK_COLOR);
delay_ms(500);
}
}*/
Baud rate : 115200
Could you please help me identify and resolve this issue?
Thank you
Hi @Berlin
Based on the information you provided,
You configured LPC865 UART for 115200 baud, but is the clock source precise enough? And does the ESP8266 expect exactly 115200?
I think you can capture the transmitted waveform and received waveform under the oscilloscope.
If the waveform is correct, you can then debug the code logic.
BR
Harry
Okay… just leave that. In UART polling method, I’m able to send data from the microcontroller to the UART0 terminal, and it works well. However, when I try to receive data, it doesn’t work. Can you give me an example code for receiving data?