2025-10-05 11:16 PM
I’m trying to establish USART communication between two STM32F407-Discovery boards, where one board acts as Master and the other as Slave.
Hardware setup
Master Board clk -> save board Clk - [common clock]
Master Board TX → Slave Board RX
Master Board RX ← Slave Board TX
Both GND connected
Using STM32F407-Discovery boards
SYNCHRONOUS MODE
connectivity configurations
USART port used (e.g., USART2)
Baud rate (e.g., 115200)
Word length (8 bits)
Parity (None)
Stop bits (1)
Clock settings ( synchronous)
clock polarity : low
clock phase : one edge
code of master and slave:
// Master
char data = 'A';
HAL_USART_Transmit(&huart2, (uint8_t*)&data, 1, HAL_MAX_DELAY);
// Slave
char rx;
HAL_USART_Receive(&huart2, (uint8_t*)&rx, 1, HAL_MAX_DELAY);
output : Im getting grbage value like 127@ , so on
What I've tried
- Verified TX/RX wiring
- Checked baud rate matching
- Tried loopback test on each board (TX→RX)
- Switched from polling to interrupt-based reception
2025-10-06 6:00 AM
Hello Mohammed
You need to initialize the USART peripheral with synchronous mode enabled and clock configured properly.
Here is a snipped code that could help you
Example initialization snippet for Master:
huart2.Instance = USART2; huart2.Init.BaudRate = 115200; huart2.Init.WordLength = UART_WORDLENGTH_8B; huart2.Init.StopBits = UART_STOPBITS_1; huart2.Init.Parity = UART_PARITY_NONE; huart2.Init.Mode = UART_MODE_TX_RX; huart2.Init.CLKPolarity = UART_POLARITY_LOW; huart2.Init.CLKPhase = UART_PHASE_1EDGE; huart2.Init.LastBit = UART_LASTBIT_ENABLE; // Important for synchronous mode HAL_USART_Init(&huart2);
For Slave, the configuration is similar but the clock is received:
huart2.Init.Mode = UART_MODE_TX_RX; huart2.Init.CLKPolarity = UART_POLARITY_LOW; huart2.Init.CLKPhase = UART_PHASE_1EDGE; huart2.Init.LastBit = UART_LASTBIT_ENABLE; HAL_USART_Init(&huart2);