i'm trying to communicate with a Wifi module (esp8266) using STM32F103, on keil IDE. As described in the schematic : i want making my stm32 send AT command to esp8266 through usart1 (Tx1), and getting the esp response (Rx1), then display the esp response on computer serial monitor using usart2 ( Tx2).
After configuring usart1 and usart2, and writing the functions to send an receive data, i'm getting only the ECHO of the command, rather than the response which should be "OK"enter code here
.
when i'm sending "AT\r\n", i'm receiving only AT on serial monitor.
i will share the code i have wrote, and the traces on logic analyzer.
if there is any suggestion i will be thankful.
int len=0;
char buff[256];
int main(void){
__disable_irq();
systick_init();
UART1_Init();
UART2_Init();
Delayms(100);
printMsg1("AT\r\n");
Delayms(100);
NVIC_EnableIRQ(USART1_IRQn);
__enable_irq();
while(1){}
}
void USART1_IRQHandler(){
if (USART1->SR & USART_SR_RXNE) // if received data (RXNE event flag is set) is ready to be read -->RXNE
{
buff[len] = USART1->DR;
Delayms(100);
printMsg2(buff);
}
}
void printMsg1(char *msg, ...) // Sending AT command to ESP ( Stm32-> ESP8266)
{
va_list args;
va_start(args,msg);
vsprintf(buff,msg,args);
for(int i=0;i<strlen(buff);i++)
{
USART1->DR = (buff[i]&0xFF);
while(!(USART1->SR & USART_SR_TXE)); //wait for TXE, 1 = data transferred
}
}
void printMsg2(char *msg, ...) // Sending ESP response to Serial Monitor ( STM32-> PC)
{
va_list args;
va_start(args,msg);
vsprintf(buff,msg,args);
for(int i=0;i<strlen(buff);i++)
{
USART2->DR = buff[i];
while(!(USART2->SR & USART_SR_TXE)); //wait for TXE, 1 = data transferred
}
}