Skip to main content
Visitor II
October 6, 2025
Question

STM32F407F4 Discovery: USART Master-Slave Communication Issue

  • October 6, 2025
  • 2 replies
  • 364 views

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



 

    This topic has been closed for replies.

    2 replies

    ST Employee
    October 6, 2025

    HAL USART Initialization

    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);
    Visitor II
    October 7, 2025

    Hello sir, Thank you for your guidance.
    I tried initializing the USART in synchronous mode using the configuration you shared. The initialization works fine, but when I send a single byte from the master to the slave, I’m receiving unexpected data (for example, value 255  in the Live Expressions during debugging).
    Could you please help me understand why I might be receiving this garbage data even though the clock and configuration seem correct?
    i will be grateful if u help me out with this

     

    ST Employee
    October 24, 2025

    I have checked your code, there is no problem. 

    How about loopback test on each board (TX→RX)? also is failed? did you have check the waveform of the TX/RX/Clock by oscilloscope?