No Response from PZEM-004T Module using USART Communication
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-21 6:20 AM - edited ‎2024-09-21 6:26 AM
I'm currently facing an issue with my custom USART driver for communicating with the PZEM-004T module. I've successfully developed and tested this driver, and it works perfectly with other devices like the ESP32, where I receive responses without any problems. However, when I attempt to communicate with the PZEM-004T, the data sent appears correctly on the logic analyzer, but I receive no response from the slave, i also tried sending the command from pc using Tera Term 5 but same. I've verified that I’m using the correct settings: a baud rate of 9600, 8 data bits, 1 stop bit, and no parity. Additionally, I've checked the Special Function Registers (SFRs) to ensure everything is set up correctly. I've also tried changing the slave address and modifying the Modbus command, but none of these adjustments have yielded any results. Any guidance or suggestions on how to troubleshoot this issue would be greatly appreciated.
I don’t believe the problem from my code as i said i already tested it with other SLAVES. I think the sensor isn’t receiving the right command or somthing, but I've checked with others who used the same command and received a reply.
I’m really struggling with this problem, and I would greatly appreciate any help anyone can offer.
Solved! Go to Solution.
- Labels:
-
STM32F4 Series
-
UART-USART
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-26 2:49 AM
I finally found a solution for communicating with the PZEM004T v3.0 module using the STM32F401xx and a custom UART driver I developed.
One important detail that stumped me for a while: to get the RX data from the sensor, you must power the PZEM004T with 220V AC. Without it, the module won't start sending data. So make sure it's properly powered before attempting any communication!
 
I’ve documented the process and shared my custom UART driver code on GitHub. Check it out here: https://github.com/Mahjoubhafien/stm32_txrx_uart_pzem004tv3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-21 7:10 AM
Is the PZEM-004T module ready-made or custom-made? If it is a customized board, please test the PCB.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-24 3:25 AM
Hello @MahjoubHafyen
Could you try with the USART HAL driver and compare the results please?
Saket_Om
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-24 3:46 AM
@MahjoubHafyen wrote:the PZEM-004T module.
What "PZEM-004T module" ?
@MahjoubHafyen wrote:it works perfectly with other devices like the ESP32, where I receive responses without any problems. However, when I attempt to communicate with the PZEM-004T, the data sent appears correctly on the logic analyzer, but I receive no response from the slave
So have you carefully compared some ESP32 logic analyser traces with some STM32 logic analyser traces?
Also try using an oscilloscope - that might show up any "analogue" oddities not visible on a logic analyser.
@MahjoubHafyen wrote:i also tried sending the command from pc using Tera Term 5 but same.
So it's only the ESP32 which works - neither STM32 nor PC works ?
Again, carefully compare the ESP32 traces against both STM32 & PC.
Are you sure you have good grounds & power supplies in both cases?
Please see the posting tips for how to properly post source code - not as a screenshot:
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-26 2:49 AM
I finally found a solution for communicating with the PZEM004T v3.0 module using the STM32F401xx and a custom UART driver I developed.
One important detail that stumped me for a while: to get the RX data from the sensor, you must power the PZEM004T with 220V AC. Without it, the module won't start sending data. So make sure it's properly powered before attempting any communication!
 
I’ve documented the process and shared my custom UART driver code on GitHub. Check it out here: https://github.com/Mahjoubhafien/stm32_txrx_uart_pzem004tv3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-26 2:57 AM
@MahjoubHafyen wrote:One important detail that stumped me for a while: to get the RX data from the sensor, you must power the PZEM004T with 220V AC. Without it, the module won't start sending data.
So, presumably, that was the difference between your working ESP32 case, and the non-working STM32 and PC cases?
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-26 3:03 AM
I mean the uart driver work between stm32 as MASTER and esp32 as SLAVE, Maybe it was a misunderstanding because I didn’t write or explain it properly, sorry about that.
