I am trying to make my Arduino Mega a receiver of 9 bits and 1 stop bit via UART.
I read a bit and saw that the Serial.available() etc library only supports 5-8 bits.
Will appreciate help and if someone can explain me the process of UART in arduino, when it receives the data bits does it automatically first send a start-bit and then the data following a stop bit? I also want to sample the bits at the middle which is the most accurate, I will have to add a delay for 1/2 time of 1 bit after the start-bit for that right?
See the data sheet for using 9 bit UART mode. Libraries exist, but mostly for sending only. Eventually you can use the SERIAL_8E1 (or O1) config and recover the 9th bit from the parity? See Serial.begin()
9-bit on AVR is tricky little bit. Arduino lib does not support it due to complications (probably) with another register need for bit#8. See the datasheet for details.
Set the port up for 8 data bits with parity checking enabled, set as either odd or even.
Read one byte at a time.
If I get any parity errors, I know that the 9th bit is the opposite of what I set.
The arduino code doesn’t check or buffer parity bits, either, so you still need to rewrite the same code that you’d rewrite to support an actual 9bit mode...
Reply #4 was written by the guy who makes the current for the last few years bootloaders.
What he knows means more than asking over and over for a cookie.
If you don't understand the 9 bit library, you may also be incapable of writing the processing of the received values. If every character has 9 bits, it has to be stored in an int, not a char, so that none of the char handling functions can be used for buffering or further processing of the input. Also no debug information can be sent to the Serial Monitor from an Uno.
You can start receiving characters by
int myIntChar = Serial.read();
after the usual setup and check for available characters. All further processing is up to you.
Do you already have an idea what you want to do with those received int's? Have you added a display to your Uno for showing what 9 bit data has arrived?
I am trying to make my Arduino Mega a receiver of 9 bits and 1 stop bit via UART.
I read a bit and saw that the Serial.available() etc library only supports 5-8 bits.
Will appreciate help and if someone can explain me the process of UART in arduino, when it receives the data bits does it automatically first send a start-bit and then the data following a stop bit? I also want to sample the bits at the middle which is the most accurate, I will have to add a delay for 1/2 time of 1 bit after the start-bit for that right?
Thanks.
You could forget about the UART and modify SoftwareSerial or write your own especially if the baud rate will not be high.
Sigh. I was intrigued. See if this works. I don't actually have any 9bit devices to test with, but it behaves the way I'd expect when talking to the normal 8bit things...
General strategy:
Let the user initialize the UART with Serial.begin(), and then use
this library to "disconnect" the UART from the normal Arduino function,
reset it to 9-bit mode (keeping any other settings), and then access the
RX and TX registers directly (no interrupts, no buffering beyond what is
provided by the hardware (2 bytes.)
Because "reasons", this is not a "stream" subclass, so the .print() methods
are not available. Just various varieties of .write()
write(uint16_t byte) // Write a 9bit byte.
write(const char *str) // quoted strings are written with bit9 = 0
write(const uint8_t *buf, size_t size); // 8bit arrays also wrirten with bit9=0
write(const char *buffer, size_t size)
write(const uint16_t *buffer, size_t size); // 16bit arrays write 9 bits from each word
westfw:
Sigh. I was intrigued. See if this works. I don't actually have any 9bit devices to test with, but it behaves the way I'd expect when talking to the normal 8bit things...Edit: oops; I had a bug in the .read() function that would cause it to not work right if called when there was no data available.
Attached zip updated. Or check out the latest version here: Duino-hacks/Serial9_test at master · WestfW/Duino-hacks · GitHub
Thanks a lot for that, how do I declare pins as RX and TX in the code with your library, do I need to include the "SoftwareSerial" and do it regularry or is it different now with this lib?