Skip to main content
Explorer
June 2, 2025
Question

UART reception fail on STM32F042KT with STPM3x IC

  • June 2, 2025
  • 2 replies
  • 389 views

Hello community,

I'm facing a UART communication issue with my STM32F042K6T6 board and would appreciate any insights. Here are the details:

Hardware Setup:

  • MCU: STM32F042K6T6
  • Peripheral: STPM3x Energy Metering IC
  • Connection: 9600 baud, 8N1, no flow control
  • Voltage levels: 3.3V on both sides

The Problem:

  • My STM32 fails to properly receive data from the STPM3x
  • However, when I check with a logic analyzer, I can see the STPM3x is transmitting valid data packets
  • The STM32 misses packets entirely even max delay provided.
  • Tried interfacing ESP32 → STPM3x works very fine.


What I've Verified:

Signal Integrity:

  • Clean waveforms visible on logic analyzer
  • Proper baud rate (9600) confirmed
  • Correct parity and stop bits

Basic Tests:

  • Loopback test (TX→RX) also not working properly as only the first byte is received others omitted.
  • Different baud rates yield same issue
  • Tried multiple GPIO pins 

NOTE : The stpm3x.h & stpm3x.c library is ported manually from CPP. I also attached the original CPP files for the reference.

    This topic has been closed for replies.

    2 replies

    Super User
    June 2, 2025

    > hal_status = HAL_UART_Receive(uart, recv, sizeof(recv), 1000);

    > Loopback test (TX→RX) also not working properly as only the first byte is received others omitted.

    You will need to use nonblocking functions to receive data as it comes in and store those into a buffer for use. There is no automatic handling of data beyond the single byte buffer--if two bytes get received and you haven't processed them yet, that will trigger an overflow, the peripheral will stop, and the data will be lost.

    Technical Moderator
    June 2, 2025