Page 1 of 1

ESP32 WROOM RS232 PROBLEM

Posted: Mon Apr 25, 2022 10:17 am
by max.tisc
Hello everybody
maybe I found a bug on the management of the RX input of the rs232 component, the jump to the macro for reading the input data is regulated by the RXINT2 interrupt, RX2 of the 232 is connected to a Nextion display that sends the bytes only once but the macro reads them for many times, I attach the test file and some screEnshoot
is this a bug or an error in my settings?
thank you

Re: ESP32 WROOM RS232 PROBLEM

Posted: Mon Apr 25, 2022 10:41 am
by BenR
Hello,

The RX_232 interrupt macro should only be collecting a single byte, you are collecting 7. So the interrupt will fire 7 times but there is no data left after the first run because you have already collected all the bytes.

What would be better is to collect a single byte and add it into a circular buffer component. You can then in your main check for the number of bytes inside the circular buffer or search the buffer for valid responses.

Re: ESP32 WROOM RS232 PROBLEM

Posted: Mon Apr 25, 2022 2:21 pm
by max.tisc
hello BenR
thanks for your answer, now I try your advice, but I can tell you that I have already used nextion on arduino mega2560 and I have never had this type of problem, maybe the interruput management between mega2560 and ESp32 is different?
thank you

Re: ESP32 WROOM RS232 PROBLEM

Posted: Mon Apr 25, 2022 3:06 pm
by BenR
Hello,
maybe the interruput management between mega2560 and ESp32 is different?
Yes sorry it looks like it is, the mega only has a boolean interrupt flag and this is cleared when we leave the interrupt and so by that time all data has been received and processed and the interrupt does not fire again.

This is not the best way to do the interrupt though as you are essentially blocking the main task any any other high priority interrupts until you have received all 7 bytes.

Looks like ESP has a counter rather than a boolean flag and hence the 7 interrupts you are receiving even after collecting the data, the ESP must be expecting you to collect things a byte at a time. Doing it using the circular buffer is a much better approach as you are not blocking inside the interrupt while the other 6 bytes come in.

Waiting around for 6 bytes @ 9600 baud would equate to 6.25ms or approx 1,500,000 potentially wasted instructions on the ESP device.

Re: ESP32 WROOM RS232 PROBLEM

Posted: Mon Apr 25, 2022 3:56 pm
by max.tisc
Hi BenR
i did as you advised me and now i only read 7 bytes
thank you