UART2 on WROOM driving me crazy

BartDP
Posts: 2
Joined: Thu Jun 24, 2021 7:18 pm

UART2 on WROOM driving me crazy

Postby BartDP » Thu Jun 24, 2021 8:28 pm

Dear reader,

I have a working ESP8266 reading out my digital electricity meter at 115200 8N1 with softwareserial in mode 'inverted signaling'
There is a hardware inverter installed between meter and ESP8266 ( by means of and BS170 mosfet and a 10k resistor)
As serial bits are inverted by hardware, software serial needs the 'inverted signaling' parameter ON
As said, this is working

As softwareserial isn't the best solution at 115200 baud, I'm missing most of the time a (set of) bits(s), so my checksum (luckly there is one at the end of each stream) is mostly invalid. So 80%-90% of the readings are not usable.

So i'm trying to switch to an ESP32 as these have 3 UART's, so I can use hardware serial. I'm trying to use UART3 (serial2) on standard port GPIO16, as 1 is connected to the USB chip and 2 connected to the flash chip
As hardware serial hasn't the 'inverted signaling' option, I'm not using an hardware inverter ( but a BS170 with 2 resistors as level shifter from 5V to 3V )

As test, I'm copying out each received byte at serial2 to serial(0) so I can monitor via Putty on my PC :

void loop() {
while (Serial2.available()) {
Serial.print(char(Serial2.read()));
}
ArduinoOTA.handle();
}

I receive the stream ( I see it each second appearing in Putty ) but it is completely human unreadable (should be readable). I see it has each time the same ending.
( as example, last bytes :
8b 99 9d a3 97 a3 9f af 8d 8d 8d ab 7d ad e5 eb 9f a5 9f 8b 8d 93 a3 9d 99 a3 9f af ad e5 eb 9f a5 9d 8b 9b 97 a3 9d a3 9f af 9f 9f 99 ad e5 eb 9f a5 9d 8b 8d 93 a3 9d a3 9d af 99 91 97 93 97 79 97 73 99
showing as ‹™£—£Ÿ¯«}­å럥Ÿ‹“£™£Ÿ¯­å럥‹›—££Ÿ¯ŸŸ™­å럥‹“££¯™‘—“—y—s™ )

Does someone has a idea here what is wrong or going on ?
Thanks for any reply !

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: UART2 on WROOM driving me crazy

Postby ESP_Sprite » Fri Jun 25, 2021 1:51 am

Hard to say, are you actually sure the signal into the ESP32 looks like a serial stream? (As in: can you use a scope or LA to confirm it's okay?) Also note that the ESP32 can invert peripheral signals in hardware, it takes a bit of an arcane incantation to do so however.

pscsuk
Posts: 2
Joined: Fri May 07, 2021 9:20 pm

Re: UART2 on WROOM driving me crazy

Postby pscsuk » Fri Jun 25, 2021 5:01 am

I don’t know if it’s relevant to you, but one thing that caught me out was that changing the CPU clock speed after initialising the hardware serial port really messed things up.

BartDP
Posts: 2
Joined: Thu Jun 24, 2021 7:18 pm

Re: UART2 on WROOM driving me crazy

Postby BartDP » Fri Jun 25, 2021 9:39 pm

Thanks for above reaction.

I finally found it myself after looking to a lot of examples.
At a certain moment i found a 'TRUE' added in the

Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2, true);

That did the trick.

Strange is I can't find this somewhere documented.

So, if receiving a lot of garbage ( but you see the appearing tempo is correct) , worth a try to invert the payload

Who is online

Users browsing this forum: No registered users and 68 guests