cancel
Showing results for 
Search instead for 
Did you mean: 

USART Configuration

khaylup
Associate

Hi,

I need help configuring a USART connection between a STM32L452RE Nucleo Board and a ESP8266-01 wifi chip. My goal is to send AT Commands from the STM32 to the ESP8266.

I currently have my USART TX and RX connected to the RX and TX respectively of my ESP8266 board, and I've noticed that the LED is flashing on the ESP8266 when debugging through these commands, indicating that a signal is indeed being sent via my USART. However, i've noticed that the data has been scrambled on send and receive, as if i change the password to my wifi hotspot, I am unable to connect to it. By piping the USART1 RX directly to my serial monitor, I noticed a significant amount of scrambling.

I have proved that this sequence of commands works as intended, and have been able to connect my ESP8266 to an arduino uno, as well as an STM32 bluepill using RX and TX in default mode, but my attempts to get my project to work on the STM32L452RE have failed.

wifi commands.jpg

The way that I am piping the commands is shown above, and the output on my serial monitor looks something like this: 

com.jpg

In terms of BaudRate, my ESP8266, USART1 and USART2 all use 115200. I have also tried the serial monitor at 9600, but haven't seen the responses that I expect as with my current piping setup i only receive one character ( A A W A).

My current USART1 configuration is shown below. 

usart.jpg

 

I'm looking for some specific guidance on how to configure my USART for this situation. I've noticed some things where it might be necessary to try the RX on Open drain, however this has brought me no luck. My .ioc and source files are provided. My ESP8266 is powered by an external voltage source, with only TX and RX connected to my STM32L4.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

Unlike Arduino, the ST "HAL" library does not do any buffering. So, sequences like this will lose the RX data:

HAL_UART_Transmit(&huart1,...);
HAL_Delay(...);
HAL_UART_Receive(&huart1,...);
HAL_UART_Transmit(&huart2,...);

 The 2nd transmit() will therefore transmit junk.

Please search and use examples of sending "AT" commands to various devices. The naïve use of the HAL library won't work. If confused and want help, get the help here.

View solution in original post

4 REPLIES 4
LCE
Principal

Before starting a new TX, check that the latest last byte has been transmitted. (while flag + tick timeout).

Even at 115k2 it takes some time to shift out some bits, so the buffer or UART FIFO gets overwritten before data is out.

Not sure how these HAL functions work, but without neither interrupt nor DMA the UART is not that "elegant".

padawan
Senior

Just one question: are the gnd from your board and esp are connected?

Can you use an Oszi to verify the levels of tx and rx? 

hth 

padawan

Andrew Neil
Evangelist

How have you verified that both your STM and your ESP are actually working at the correct baud rate?

Can your STM on its own successfully communicate with a PC terminal?

Can your ESP on its own successfully communicate with a PC terminal?

See also:

https://community.st.com/t5/stm8-mcus/uart-communication/m-p/630047/highlight/true#M9785

 

Pavel A.
Evangelist III

Unlike Arduino, the ST "HAL" library does not do any buffering. So, sequences like this will lose the RX data:

HAL_UART_Transmit(&huart1,...);
HAL_Delay(...);
HAL_UART_Receive(&huart1,...);
HAL_UART_Transmit(&huart2,...);

 The 2nd transmit() will therefore transmit junk.

Please search and use examples of sending "AT" commands to various devices. The naïve use of the HAL library won't work. If confused and want help, get the help here.