cancel
Showing results for 
Search instead for 
Did you mean: 

UART reception fail on STM32F042KT with STPM3x IC

Muruganandam
Associate II

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.

2 REPLIES 2
TDK
Super User

> 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.

If you feel a post has answered your question, please click "Accept as Solution".
Saket_Om
ST Employee

Hello @Muruganandam 

Please refer to the UART example below:

STM32CubeF0/Projects/STM32F042K6-Nucleo/Examples/UART/UART_TwoBoards_ComIT at master · STMicroelectronics/STM32CubeF0 · GitHub

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om