Page 1 of 1

9 Bit UART

Posted: Mon Jan 14, 2019 6:29 pm
by mr_darker
Hello, I have a need to use 9 bit communications with the ESP32. 1 start bit, one stop bit, and 9 data bits.

ESP32 supports up to 8 data bits, but it is possible to use a parity bit to send data.

To send, we can reconfigure the parity "polarity" prior to sending each byte, in order to control if it is one or zero. We may also be able to just manually enter the parity bit into registers, but I haven't looked into that yet.

In the technical reference manual, it sounds like we might be able to just receive data with a bad parity, and read it anyways, then figure out what the parity is. If the UART hardware doesn't let you read data that came with a bad parity, there seems to be the option to read data bit by bit as it comes in and manually transfer each bit to storage.

Does anyone know if the first method for receiving 9 bit data would work? It doesn't seem to say, since it's using the parity bit in a way it isn't meant for. I don't have a development board so can't try it out.


Also would anyone happen to know off the top of their head if the coprocessor is connected to the UART? Because doing things bit by bit would take up a measurable amount of processing time. It'd be like bitbanging, except using the UART hardware for timing and all that.

Re: 9 Bit UART

Posted: Tue Oct 29, 2019 1:43 am
by ionini
Hi!
I came across this problem and couldn't find anything.
But, I forked the SoftwareSerial library for the ESP32 and modified it a bit so 9 bit frames work.
Here you go!
https://github.com/ionini/espsoftwareserial
Hope someone finds this useful.

Re: 9 Bit UART

Posted: Fri May 15, 2020 1:02 pm
by peter_moulin
ionini wrote:
Tue Oct 29, 2019 1:43 am
Hi!
I came across this problem and couldn't find anything.
But, I forked the SoftwareSerial library for the ESP32 and modified it a bit so 9 bit frames work.
Here you go!
https://github.com/ionini/espsoftwareserial
Hope someone finds this useful.
I have tried your library with an ESP32 board compiled on Arduino IDE, but I get an error.
Hereafter the feedback from compile:
Hope that you can help me,

Pierre

D:\Pierre\Documents\Arduino\libraries\espsoftwareserial-master\src\SoftwareSerial.cpp: In member function 'void SoftwareSerial::enableRx(bool)':
D:\Pierre\Documents\Arduino\libraries\espsoftwareserial-master\src\SoftwareSerial.cpp:140:100: error: invalid conversion from 'void (*)()' to 'void (*)(void*)' [-fpermissive]
attachInterruptArg(digitalPinToInterrupt(m_rxPin), (void (*)())(rxBitISR), this, CHANGE);
^
In file included from C:\Users\peter\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/esp32-hal.h:53:0,
from C:\Users\peter\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Arduino.h:35,
from D:\Pierre\Documents\Arduino\libraries\espsoftwareserial-master\src\circular_queue/circular_queue.h:24,
from D:\Pierre\Documents\Arduino\libraries\espsoftwareserial-master\src\SoftwareSerial.h:27,
from D:\Pierre\Documents\Arduino\libraries\espsoftwareserial-master\src\SoftwareSerial.cpp:23:
C:\Users\peter\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/esp32-hal-gpio.h:82:6: note: initializing argument 2 of 'void attachInterruptArg(uint8_t, void (*)(void*), void*, int)'
void attachInterruptArg(uint8_t pin, void (*)(void*), void * arg, int mode);
^

exit status 1
Erreur de compilation pour la carte ESP32 Wrover Module

Re: 9 Bit UART

Posted: Fri Apr 15, 2022 7:42 am
by ecevitbatu
Hello Guys,
I have some problem. I use 9 bit for this ,i should software uart.Can you help me and can you share an example with me.

Re: 9 Bit UART

Posted: Mon Jan 09, 2023 2:27 pm
by pnn_69
Same here

Re: 9 Bit UART

Posted: Tue Apr 18, 2023 9:21 am
by auric_ant
if this is the only problem, then I took the code from a similar library, edit the SoftwareSerial.cpp file, the function void SoftwareSerial::enableRx(bool on), change the line

Code: Select all

attachInterruptArg(digitalPinToInterrupt(m_rxPin), (void (*)())(rxBitISR) , this, CHANGE);
to

Code: Select all

attachInterruptArg(digitalPinToInterrupt(m_rxPin), reinterpret_cast<void (*)(void*)>(rxBitISR), this, CHANGE);