Author Topic: STM32Cube UART Transmit Function Bug  (Read 948 times)

0 Members and 1 Guest are viewing this topic.

Offline edsTopic starter

  • Newbie
  • Posts: 5
  • Country: 00
STM32Cube UART Transmit Function Bug
« on: March 06, 2024, 01:21:49 pm »
Hello everyone,

I am trying to learn the basics of STM32CubeIDE and Embedded C programming. I have a microcontroller that I am trying  to program and see how it works step by step. For the first subject, I am trying to see something I am transmitting via UART to the PC. I am trying to transmit "Hello World!" It is just a two line code so I do not know where I am making a mistake. I believe it is a problem with the timing as I am receiving my message in full if I run the function in debug mode line by line.

Code: [Select]
  while (1)
  {
    /* USER CODE END WHILE */
  HAL_UART_Transmit(&huart1, startupMessage, 13, 10000);
  HAL_Delay(1000);
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

I am initializing everything before the while loop and also I am sure my Baud Rate, Parity Bits etc. settings are right. This is the output I am getting.
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5913
  • Country: es
Re: STM32Cube UART Transmit Function Bug
« Reply #1 on: March 06, 2024, 02:56:10 pm »
Nothing obvious, post the rest of the code (Specially startupMessage init) or upload the project, never had any issue with this.
Also, normally you don't transmit the null termination:
Code: [Select]
HAL_UART_Transmit(&huart1, startupMessage, 12, 10000);
Try:
Code: [Select]
HAL_UART_Transmit(&huart1, "Hello World!\r\n", 14, 10000);
« Last Edit: March 06, 2024, 03:02:58 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline darkspr1te

  • Frequent Contributor
  • **
  • Posts: 290
  • Country: zm
Re: STM32Cube UART Transmit Function Bug
« Reply #2 on: March 06, 2024, 05:54:06 pm »
you need to check the status of the UART before sending again ,
use something like
while (HAL_uart_check_status(&uartname) ==1) {}
this adds a delay that is based on the UART status register.




i'am not sure of the ST HAL call for this as i moved away from HAL and use HAL_LL_ or use my own libs




darkspr1te

 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5913
  • Country: es
Re: STM32Cube UART Transmit Function Bug
« Reply #3 on: March 06, 2024, 09:20:51 pm »
Not required, HAL_UART_Transmit does this before and after transmitting.

But the OP should be checking if the function returns HAL_OK:

Code: [Select]
if(HAL_UART_Transmit(&huart1, startupMessage, 12, 10000) != HAL_OK){
    // Error
}
« Last Edit: March 06, 2024, 09:27:58 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline dietert1

  • Super Contributor
  • ***
  • Posts: 2073
  • Country: br
    • CADT Homepage
Re: STM32Cube UART Transmit Function Bug
« Reply #4 on: March 06, 2024, 09:38:39 pm »
The OP needs to put his code into user code begin .. - user code end .. sections. Otherwise his code that may have been working will disappear when using CubeMX to generate another version of the project. This is very important to learn as fast as possible.

Regards, Dieter
 

Offline darkspr1te

  • Frequent Contributor
  • **
  • Posts: 290
  • Country: zm
Re: STM32Cube UART Transmit Function Bug
« Reply #5 on: March 07, 2024, 04:51:56 am »


Quote from: dietert1 on Yesterday at 11:38:39 pm
The OP needs to put his code into user code begin .. - user code end .. sections. Otherwise his code that may have been working will disappear when using CubeMX to generate another version of the project. This is very important to learn as fast as possible.

Regards, Dieter


Yup, learned that one the hard way too.

darkspr1te
 

Offline tellurium

  • Regular Contributor
  • *
  • Posts: 231
  • Country: ua
Re: STM32Cube UART Transmit Function Bug
« Reply #6 on: March 08, 2024, 04:09:45 am »
If you want to learn how uC works, do not use Cube HAL or any other framework.
Learn on bare metal. See

https://github.com/cpq/bare-metal-programming-guide
Open source embedded network library https://mongoose.ws
TCP/IP stack + TLS1.3 + HTTP/WebSocket/MQTT in a single file
 

Offline dietert1

  • Super Contributor
  • ***
  • Posts: 2073
  • Country: br
    • CADT Homepage
Re: STM32Cube UART Transmit Function Bug
« Reply #7 on: March 08, 2024, 06:50:15 am »
Don't trust some strange github project.
Use the "official" ST support including their free tools like CubeMX. A beginner should learn those tools as they speed up getting results.

Regards, Dieter
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5913
  • Country: es
Re: STM32Cube UART Transmit Function Bug
« Reply #8 on: March 08, 2024, 08:26:36 am »
OP never came back, stop this no sense lol
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf