9 Bit UART

mr_darker
Posts: 3
Joined: Thu Dec 27, 2018 11:37 am

9 Bit UART

Postby mr_darker » Mon Jan 14, 2019 6:29 pm

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.

ionini
Posts: 1
Joined: Tue Oct 29, 2019 1:41 am

Re: 9 Bit UART

Postby ionini » 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.

peter_moulin
Posts: 6
Joined: Fri May 15, 2020 12:48 pm

Re: 9 Bit UART

Postby peter_moulin » Fri May 15, 2020 1:02 pm

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

ecevitbatu
Posts: 5
Joined: Fri Apr 15, 2022 7:18 am

Re: 9 Bit UART

Postby ecevitbatu » Fri Apr 15, 2022 7:42 am

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.

pnn_69
Posts: 1
Joined: Tue Jun 04, 2019 2:01 pm

Re: 9 Bit UART

Postby pnn_69 » Mon Jan 09, 2023 2:27 pm

Same here

auric_ant
Posts: 1
Joined: Tue Apr 18, 2023 9:17 am

Re: 9 Bit UART

Postby auric_ant » Tue Apr 18, 2023 9:21 am

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);

Who is online

Users browsing this forum: Baidu [Spider], markkuk and 75 guests