2019-03-15 08:16 AM
Hi,
my first example for RS232 communication and my first problem.
I have this output in the terminal:
5 ''! Ëå˙˙˙ <00> 5 ''! Ëå˙˙˙ <00> 5 ''! Ëå˙˙˙ <00> 5 ''! Ëå˙˙˙ <00> 5 ''! Ëå˙ <00> 5 ''! Ë <00> 5 ''! Ëå˙˙˙ <00> 5 ''! Ëåë <00> 5 ''! Ëåë <00> 5 ''! ëå˙˙˙ <00> 5 ''! ëå˙˙˙ <00> 5 ''! ëå˙˙˙ <00> 5 ''! ëå˙˙˙ <00> 5 ''! ëå˙˙ 00 <00> 5 ''!
...
I can use another board (processor), but the result is the same.
Tested on STM32F407VE, STM32F103, ...
My code is very simple:
uint8_t data[10] = "Hello\n\r";
while (1)
{
HAL_UART_Transmit(&huart2, data, 10, 100);
HAL_Delay(100);
}
Speed and other communication parameters on both sides the same
Some idea.
Thank you
2019-03-15 10:37 AM
First, you are telling HAL_UART_Transmit() to send 10 bytes from data[]. Given your definition of data, it contains "Hello\r\n\0\0\0". The first NULL is the NULL terminator that "C" puts in all string constants, and the other two NULLs are zero padding that "C" uses to pad incomplete array (and structure) initialization. Do you really want to send those NULL characters? If not, change the "10" to "7" in the HAL_UART_Transmit() call. Better yet, use strlen(data) if you know you are always going to send human-readable text.
Second - what do you have this board connected to that receives the async serial data? Is it a PC or another microcontroller? If it is a PC, HOW do you have them connected? If you are using a serial port on the PC, or a USB-to-RS232 adapter, it is expecting real RS-232 (aka EIA-232 or whatever it is now called) signal levels, not 3.3V TTL signal levels. Or are you using a USB-to-TTL Serial adapter, in which case you CAN connect it directly to the CPU pins.
Third, if you have an oscilloscope available, look at the transmit data from your CPU and make sure the bit times are what you expect for whatever baud rate you choose. Presuming you posted the exact response that you see in the terminal, it looks like you are receiving a 13 or 14 character repetetive pattern, while you are sending a 10 character pattern. That implies the actual baud rates are not the same.
2019-03-15 10:54 AM
Check the baudrate and the USART reference clock speed, and also what is the clock source spread. Try 9600bps first.