Skip to main content
Associate III
June 10, 2024
Question

UART reception isssue

  • June 10, 2024
  • 12 replies
  • 4370 views

Hello everyone,

I am working with a STM32WB5MMDK. I want to use the USART to print a message on Tera Term but i just have inversed triangles instead of "Hello world". I checked and both Tera Term and USART1 have the same parameters (baud rate, etc). I find it weird that i have a succession of triangles, and the other subjects related don't mention that.

Does anyone know how to fix this ?

Thank you

This topic has been closed for replies.

12 replies

Andrew Neil
Super User
June 10, 2024

@Nour wrote:

i just have inversed triangles instead of "Hello world".


The most common reason for seeing "junk characters" is wrong baud rate:

https://learn.sparkfun.com/tutorials/serial-communication/all#:~:text=If%20all%20the%20receiving%20device%20sees%20on%20its%20receive%20line%20is%20garbage%2C%20check%20to%20make%20sure%20the%20baud%20rates%20match%20up.

 

How did you verify that your STM32 is actually transmitting at the correct baud rate? The best way is to use an oscilloscope to check ...

 


@Nour wrote:

I find it weird that i have a succession of triangles, and the other subjects related don't mention that.


"junk" characters can take any form!

 

One think to note specifically with TeraTerm is that it can misinterpret "junk" characters as control codes, and so it ends up in some weird "graphics" mode - where it displays all received characters as strange glyphs ...

So it might be worth also checking some  other terminals ...

 

#JunkCharacters #WrongBaudRate #SerialComms

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
NourAuthor
Associate III
June 10, 2024

Well, I just checked that the baud rate of Tera Term and for the UART were the same...

I wanted to start from the example given by STM32CubeIDE but their example doesn't work either.

So, I tried with HyperTerminal, and I get just 'H'. So, it seems to be cut ?

Since I got one letter, I don't know if it is the correct baud rate (it was 115200 bits/s, the one by default, i didn't change it, and same for the clock).

Andrew Neil
Super User
June 10, 2024

@Nour wrote:

Well, I just checked that the baud rate of Tera Term and for the UART were the same...


But, again, how did you check what the baud rate coming out of the UART actually was?

 


@Nour wrote:

So, I tried with HyperTerminal, and I get just 'H'.


So you got the first character of "Hello, world", then?

This suggests the the communication is actually working - but your code is getting "stuck" after the 1st character.

Use the debugger to investigate what's happening in your code ...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
NourAuthor
Associate III
June 10, 2024

I am a beginner so i don't know how to check the real baud rate :grinning_face_with_sweat:

I changed the sentence, and I have again strange characters so I think that the H wasn't really the first character (because it can't receive well 'u' for example). I, then, doubt that the communication is really working.

Andrew Neil
Super User
June 10, 2024

@Nour wrote:

I am a beginner so i don't know how to check the real baud rate :grinning_face_with_sweat:


Again, The best way is to use an oscilloscope to check ...

Get the UART transmitting just a continuous stream of uppercase 'U' to give you a steady waveform to look at.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
NourAuthor
Associate III
June 10, 2024

I will, but i have to then check the PINS of the USART1 on my board with the oscilloscope ? because i wasn't sure about where to check the right signal.

Andrew Neil
Super User
June 10, 2024

Yes, you need to look at the TX pin of your UART.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
jumman_JHINGA
Senior III
June 10, 2024

Not selecting input crystal frequency properly, may affect baudrate and garbage data will get recevied or transmitted.

NourAuthor
Associate III
June 10, 2024

Hello, so I used an oscilloscope and I've found 1428 bauds. But, when I put 1200 or 2400 (the closer baud rates) for my hyperterminal, it still doesn't work.

The input crystal frequency is in the .ioc ?

Thank you

Andrew Neil
Super User
June 10, 2024

@Nour wrote:

 I used an oscilloscope and I've found 1428 bauds.


So there is something wrong with your configuration. That's not a standard baud rate, so it's not going to work with a terminal like Tera Term.

Baud rates need to match within a few percent.

 


@Nour wrote:

The input crystal frequency is in the .ioc ?


Yes - on the 'Clock Configuration' page
 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
NourAuthor
Associate III
June 10, 2024

I am sorry, i just want to make sure we are talking about the same thing because i am not sure i am understanding well. I have that in the clock configuration, it 's what i need to change ?
Capture d'écran 2024-06-10 161844.png

Andrew Neil
Super User
June 10, 2024

You need to show the full 'Clock Configuration' page.

Also tell us what clock source you are using - an external crystal or crystal oscillator would be best to get the accuracy required for async serial comms

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
NourAuthor
Associate III
June 10, 2024

I am sorry, here is the full page (tell me if you can't see well).

 Capture d'écran 2024-06-10 163450.pngCapture d'écran 2024-06-10 163514.png

For the clock, i don't really do anything, i let the seetings by default, i didn't really know how the clock configuration worked...

Thank you @jumman_JHINGA i will take a look

Andrew Neil
Super User
June 10, 2024

It looks like you're using MSI RC as your clock source? That may not be accurate enough as a baud rate clock.

Again, an external crystal (or crystal oscillator) would be best to get the accuracy required for async serial comms

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
NourAuthor
Associate III
June 10, 2024

Would you have any ressource on internet where I can find how to configure an external crystal ?

 

Because, I can't see well the images of @jumman_JHINGA 

jumman_JHINGA
Senior III
June 10, 2024

In PLL Source MUX select HSI instead of MSI ... after again you have to select HCLK as maximum. 

To select external crystal frequency

you need to go  to RCC setting and select Cystal Resonator for HSE.

For more details I'll suggest you to go through with the Datasheet of yours device. 

Tesla DeLorean
Guru
June 10, 2024

Check you're not using ODD parity, some of ST's examples like to use that.

Some UART can't get to lower baud rates due to the width of the BRR and the clock source. Check you aren't getting errors from HAL_UART_Init(), and perhaps divider UART->BRR back into the bus/uart clock to see the speed.

The logic levels can also be different RS232 != CMOS 3V

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..