r/embedded • u/Ok-Regular2199 • Apr 02 '26
How does ESP01 works??
I’m working on an LPC2129 + ESP-01 project. Before sending temperature data to ThingSpeak, I’m testing ESP-01 using an AT command.
Setup:
MCU: LPC2129
ESP-01 connected to UART0 (P0.0 TXD0, P0.1 RXD0)
Baud: 9600
LEDs are active LOW
Sending "AT\r\n" to ESP-01
Expecting "OK" response
Logic:
Send "AT\r\n"
Wait for UART response
If "OK" received → blink LED with 2-second delay
Else → blink another LED
Problem: When ESP-01 is connected, the LED turns ON and stays ON continuously (no blinking).
More importantly: Even after I remove the ESP logic and try a simple LED blink code, the LED still stays ON. Only after I erase flash completely and reprogram, the LED blink works normally again.
So it seems like:
Either UART receive is blocking
Or buffer logic is stuck
Or MCU is stuck inside UART wait loop
Or ESP continuously sending data and program never reaches LED OFF
Example behavior:
Simple LED blink → works
Add ESP code → LED always ON
Remove ESP code → still always ON
Full erase + reflash → blink works again
Has anyone seen this with LPC2129 + ESP-01? Is UART blocking causing the MCU to never reach the LED OFF code? What is the proper way to read ESP response without locking the CPU?
include <lpc21xx.h>
include <string.h>
define led (1<<10)
define led1 (1<<15)
void delay(unsigned int d) { T0PR =15000-1; T0TCR=0X01; while(T0TC<d); T0TCR=0X03; T0TCR=0X01; }
void uart0_init() { PINSEL0 |= 0x05;
U0LCR = 0x83;
U0DLL = 97;
U0DLM = 0;
U0LCR = 0x03;}
void uart0_tx(unsigned char data) { while(!(U0LSR & (1<<5))); U0THR = data; }
unsigned char uart0_rx() { while(!(U0LSR & (1<<0))); return U0RBR; }
void uart0_string(char *p) { while(*p) uart0_tx(*p++); }
int main() { char ch[3]; // only "OK" int i=0;
IODIR0 = led | led1;
uart0_init();
delay(1000);
while(1)
{
uart0_string("AT\r\n");
delay(200);
i=0;
ch[i++] = uart0_rx();
ch[i++] = uart0_rx();
ch[i] = '\0';
if(!strcmp(ch,"OK"))
{
IOSET0 = led; // LED ON
delay(500);
IOCLR0 = led;
}
else
{
IOSET0 = led1;
delay(500);
IOCLR0 = led1;
}
}}
1
u/Slight_Computer_6820 Apr 02 '26
Which compiler are you using ?