Pages: [1]   Go Down
Author Topic: 9-bit serial implementation  (Read 812 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I need to communicate to a serial device that uses 9-bit serial. I have found the way to set the UART for 9 bit serial but I have not found how to read and write the 9th bit. I am thinking it may be the UCSR0B Bit #0 and 1 but that that is pure guess. Is there any documentation on how to read and write the 9th bit of the data byte? Thanks for any assistance.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 443
Posts: 23837
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried the datasheet for your device?
Maybe all it takes is a simple ass'y command or two.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for pointing out the obvious. Sometimes I need that. For the the Uno, this seems to be the ATmega8U2/16U2 datasheet which states "If 9-bit characters are used (UCSZn = 7), the ninth bit must be written to the TXB8 bit in UCSRnB before the low byte of the character is written to UDRn." And for receive "the ninth bit must be read from the RXB8n bit in UCSRnB before reading the low bits from the UDRn." Just wanted I wanted to know. Thanks for the nudge in the right direction.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here:

http://arduino.cc/forum/index.php/topic,91377
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Nick. You just made my job 95% easier. I will give it a try in a few minutes. I've been in this business for nearly 40 years and never had to do serial at 9 bits. Don't ya just love odd ball hardware!
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Me too. They are just playing with the parity bit basically, so I suppose you could say it sort-of has been done before. Effectively they are switching between mark and space parity on the fly. Still, I agree it is pretty oddball.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I wanted to thanks the one who wrote the 9bit hardwareserial. It saved me an headache.
For people waiting to write their own xpressnet throttle with an arduino, i used the hardwareserial class with a mega 2560 : if people are interested i put it on github: https://github.com/nzin/xpressnet_arduino

With a basic schema:


And for people speaking french, there is my first basic implementation 



I hope it can help and serve others.

The alone thing that i'm not happy with is the flush method after writing data on the serial link. It is not working as i was expecting, so i used delay() before telling the rs485 to switch back to listening state
« Last Edit: May 10, 2013, 06:03:47 pm by nzin » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The alone thing that i'm not happy with is the flush method after writing data on the serial link. It is not working as i was expecting, so i used delay() before telling the rs485 to switch back to listening state

Which version of the IDE do you have? The flush issue has only recently been fixed.
Logged

Pages: [1]   Go Up
Jump to: