First of all I swaped UART0 to GPIO15 (TX) and GPIO13 (RX), (Luckily the Tx of HLW8032 is connected to GPIO13 in my hardware design and This is the UART0 RX pin after swap). Then I analyzed the data coming and the results were the same as of that SoftwareSerial i.e the registers overflows.
Then I used an HLW8032 LibraryHLW8032 Library (Which I've forked and will make changes for improvements) which only works on HardwareSerial, and the values are perfect. The way the library reads Serial is quite different.
So in short my issue resolved using two things:
- I swaped UART0 to GPIO15 and GPIO13 using
Serial.swap() - Used a library for the HLW8032library for the HLW8032
Thanks to @Juraj who provided the useful link about Serial Swap in ESP8266.
Serial uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX). Serial may be remapped to GPIO15 (TX) and GPIO13 (RX) by calling Serial.swap() after Serial.begin. Calling swap again maps UART0 back to GPIO1 and GPIO3.
#include "HLW8032.h"
HLW8032 HL;
void setup()
{
HL.begin(Serial,4);
Serial.begin(4800);
Serial.swap();
}
unsigned int V;
void loop()
{
HL.SerialReadLoop();
if(HL.SerialRead == 1)
{
V = HL.GetVol();
}
}
With this I can't print and see my debug prints on GPIO1 (TX) and GPIO3 (RX), but at least without changing a bit in the hardware, my design works fine.