cancel
Showing results for 
Search instead for 
Did you mean: 

No Response from PZEM-004T Module using USART Communication

MahjoubHafyen
Associate II

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.

Screenshot 2024-09-21 135602.pngIMG_20240921_135614_492.jpg

Screenshot 2024-09-21 142459.png

1 ACCEPTED SOLUTION

Accepted Solutions
MahjoubHafyen
Associate II

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!

4160c0ae5dff33c75db8eff364d4e8eb63e130d7_2_690x388.jpeg

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

View solution in original post

6 REPLIES 6
liaifat85
Senior III

Is the PZEM-004T module ready-made or custom-made? If it is a customized board, please test the PCB. 

Hello @MahjoubHafyen 

 

Could you try with the USART HAL driver and compare the results please? 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar
Andrew Neil
Evangelist III

@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:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 

MahjoubHafyen
Associate II

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!

4160c0ae5dff33c75db8eff364d4e8eb63e130d7_2_690x388.jpeg

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


@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?

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.