Skip to main content
mdiro
Associate III
June 30, 2023
Solved

Problem with UART transmission

  • June 30, 2023
  • 3 replies
  • 1768 views

Hi everyone,

Do you think there is any reason why a set of instructions (20 lines max.), including UART transmission, works fine within the while(1) block but it doesn't work if that exact set of instruction is in a function, within the same while(1) block? In practice it seems to transmit correctly unless the instructions are in a separate function. I am running out of ideas.

If necessary, I will be happy to provide more details.

Thank you!

Edit: when I say that I doesn't transmit correctly, I mean that only 2 out of 6 packets are sent. When the instructions are not in the function and directly in the while block  all the packets are send correctly. 

This topic has been closed for replies.
Best answer by Pavel A.

Among possible reasons: very marginal timing. A function call takes few more instructions. A problem with stack: is it located in some unfortunate place? And so on. In this business, every bit of difference matters.

3 replies

Bubbles
ST Employee
June 30, 2023

Hello, this is not something that anybody would be expecting, from your description it doesn't sound like any error that happens to lot of users.

You may need to provide more details. When you debug the code, do the HAL actually manipulate the UART registers? Are there any error flags in the UART status register?

BR,

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
mdiro
mdiroAuthor
Associate III
June 30, 2023

Dear J, 

thank you for your reply. Please tell me which kind of detail can help you understanding the problem. 

To your questions, yes the HAL manipulate the UART registers and I do not see any error in the status register :(. 

The thing that is even weirder is that the code was actually working fine and then suddenly it stopped working. Can be that something broke in the MCU, or that I unintentionally changed any setting in the .ioc file?

Bubbles
ST Employee
June 30, 2023

Hi, the ioc file doesn't matter unless you regenerate the project from the CubeMX again. And the ioc file only initializes the peripheral, so if something is wrong with that, you'd see no communication at all.

Probably best if you attach the ioc file and the source code you modified so we can take a look.

Are you using Nucleo, or your own board?

BR,

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
LCE
Principal II
June 30, 2023

Details:

Show the code that works and show the code that does not work.

Pavel A.
Pavel A.Best answer
Super User
June 30, 2023

Among possible reasons: very marginal timing. A function call takes few more instructions. A problem with stack: is it located in some unfortunate place? And so on. In this business, every bit of difference matters.