commx93 wrote:I need to transfer frames of 9bits over UART (9 data bits + no parity + 1 stop bit). Having already checked, I see there is no native support for 9bit data frames on ESP32. However, I'd like to ask if the following is possible?
When transmitting:
1. Construct the 9 bits that need to be transferred.
2. Observe the 9th bit, depending on its value, set the parity to either odd or even so that the parity bit would be equal to the 9bit.
3. Transmit the 8bit frame (and automatically the parity bit that represents the 9th bit).
When receiving:
1. Get the received 8bit frame. Get the parity check result.
2. Depending on the currently set parity, calculate what would be considered the "valid" bit for the selected parity. Then, based on whether there was a parity success/error, find out what the 9th bit is.
I need to know:
- Would this approach work on ESP32?
- Does the chip retain the 8 bits received over RX even in the case of parity check error (or does it empty the register in such case automatically)?
Re: UART 9bit workaround?
-
- Posts: 2
- Joined: Mon Aug 13, 2018 12:56 pm
Re: UART 9bit workaround?
Re: UART 9bit workaround?
I have the same necessity, to comunicate using 9 data bits at 115200 (SerialSoftware not posible). Could workaround using Parity changing before each byte transfer but i thing it must have a better solution. Sending a fixed 0 at parity bit could be a solution, but don´t know if possible ( the parity fixed at 1 could be simulated setting 2 stop bits).
Can someone help?
Can someone help?
Re: UART 9bit workaround?
I vaguely remember doing this a long time ago on a different platform.
IIRC what I did was
1) set UART to even parity
2) determine the parity of the 8 bits (1 or 0) assuming even parity
3) if the parity bit agrees with the 9th bit (i.e. bit 9 is 1 and parity is 1) send using even parity, if not, change UART to odd parity.
On the receiver, if you receive a parity error you can "flip the bit" for the 9th bit.
You have to be sure the UART is empty before sending a word, however.
Yes it should work on the ESP but you have to test it carefully. Systems typically do not discard a "bad" byte.
IIRC what I did was
1) set UART to even parity
2) determine the parity of the 8 bits (1 or 0) assuming even parity
3) if the parity bit agrees with the 9th bit (i.e. bit 9 is 1 and parity is 1) send using even parity, if not, change UART to odd parity.
On the receiver, if you receive a parity error you can "flip the bit" for the 9th bit.
You have to be sure the UART is empty before sending a word, however.
Yes it should work on the ESP but you have to test it carefully. Systems typically do not discard a "bad" byte.
Last edited by BrianP on Sat Jun 19, 2021 1:19 pm, edited 1 time in total.
Who is online
Users browsing this forum: No registered users and 70 guests