2018-10-24 09:16 AM
Hello everyone,
I'm trying to connect UART to my board. I've followed many tutorials on youtube but it still does not work properly. I can't see Hello World on COM6.
Board: STM32L053C8
I followed this tutorial:
https://www.youtube.com/watch?v=d6MZHdgCQx0
/* USER CODE BEGIN 0 */
uint8_t myTxData[13] = "Hello World\r\n";
/* USER CODE END 0 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_UART_Transmit(&huart2, myTxData, 13, 10);
HAL_Delay(1000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
2018-10-24 10:06 AM
STM32L053C8 is a chip, not a board, assume you have a DISCO board, rather than a NUCLEO, but helps to be specific.
Get the manual for the board you have, and review the schematic. Make sure the pins are consistent with what you are configuring.
Use strlen() for strings, or sizeof()-1 to account for the NUL, try to avoid constants you have to replicate in multiple places, the compiler can figure out the length of an array.
Have a timeout that is longer.
Examine peripheral registers and clocks via debugger.
2018-10-31 12:39 PM
Thank you for your reply!
Now I have configured USART1.
/* USER CODE BEGIN Includes */
uint8_t tx_buff[]={1};
uint8_t rx_buff[10];
while (1)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_UART_Transmit_DMA(&huart1,tx_buff,sizeof(tx_buff));// Sending in DMA mode
HAL_Delay(1000);
}
To RX,TX pins I connected FT232RL FTDI module.
With Arduino it works but with STM32 in terminal I get only symbols. Maybe someone could explain me how to correctly set the format?
Also there is a full code of main.c:
2019-09-11 04:38 AM
Most probably you already have found the answer since almost a year has passed from your last post..
Anyway this is because of wrong Baud Rate. By checking the USART1 initilization function I've notice that there is a typo on "huart1.Init.BaudRate = 9800;" so you just need to correct it to "huart1.Init.BaudRate = 9600;" and you will see the corect data on your terminal.
2019-09-12 01:45 PM
It's a 2% error, not very likely to result in completely unlegible transfer.
Maybe the clock is misconfigured, more precisely, the variable holding the supposed system frequency used in the baudrate calculation (I don't use Cube/HAL).
JW
2019-09-13 02:06 AM
You are right, normally you could see the correct data even with a 5% error. However I had a similar experience using one of those modules which probably had a counterfeit FT232RL IC.
Yes, the baud rate error could be caused from a clock missconfiguration, although the CubeMX sets the Clock configuration automatically for the selected board. If he just followed that tutorial without touching the clock configuration section in CubeMX it should work.