View previous topic :: View next topic |
Author |
Message |
trend
Joined: 02 Jan 2005 Posts: 3
|
Posted: Tue Feb 01, 2005 7:27 am Post subject: 9bit UARTs |
|
|
Hello, I have a device that communicates serially.. but with 9n1.. 1
start, 8 data bits + 1addressing bit, + 1 stop.
How do I setup the 2nd UART on an AVR for this?
I saw this code whenI was searchingaround:
CONFIG COM2 = Dummy , Synchrone = 1 , Parity = None , Stopbits = 1 ,
Databits = 9 , Clockpol = 0
but.. the guy said he got compilation errors when he tried to
compile it..
2ndly,
Could I still use a max232 chip to shift the voltages? basically I
am wondering if the max232 operates on the low level voltages.. and
doesn't actually care what data is going across the line.
thanks guys!
Lee |
|
Back to top |
|
|
naicheben
Joined: 18 Nov 2004 Posts: 47 Location: Leck
|
Posted: Tue Feb 01, 2005 8:32 am Post subject: |
|
|
the max232 does't care about the Datas send through it. It's just a levelconverter. Sounds as if you used the part before so just use it like in other applications.
regards,
Ingmar |
|
Back to top |
|
|
trend
Joined: 02 Jan 2005 Posts: 3
|
Posted: Tue Feb 01, 2005 4:07 pm Post subject: |
|
|
ok, that is what I thought.. but just wanted to double check.
thanks!
Now anyone know how to set uarts up for 9bit ?
thanks-Lee |
|
Back to top |
|
|
DToolan
Joined: 14 Aug 2004 Posts: 1384 Location: Dallas / Fort Worth, Texas (USA)
|
Posted: Tue Feb 01, 2005 10:38 pm Post subject: |
|
|
To set up a usart for 9-bit communications you have to SET UCSR0A.0 (usart zero, bit zero) or SET UCSR1A.0 (usart one, bit zero... these names may vary depending on your chip). This bit in usart control register A represents the MPC bit. This instructs the usart to generate a received character interrupt on reception of address character only (this is when the 9th bit is set). This also means you will need to enable the usart's RXC interrupt, enable all interrupts and have an RXC interrupt routine for the usart in question.
Upon reception of an address character, the interrupt service routine for that usart will be vectored to. You will need to test this address character for whatever address you decide to trigger on. When you have an address match, you RESET UCSR0A.0 or UCSR1A.0 so the usart will generate interrupts for the incoming data characters attributed to that address.
Most protocols have either a set frame size (number of characters following address) or an end of frame character. You will need to test for this condition in the data stream. Also, most protocols have a timeout period in case a frame is interrupted in mid-stream.... this you will also need to test for.
Upon detecting end of frame or timeout... you again SET UCSR0A.0 or UCSR1A.0 to enable interrupts on address characters only. This restarts the whole process and ignores data characters (characters without the 9th bit set).
I'd be surprised if this interface was RS232 as most multi-drop addressing is done over an RS485 or similar interface. |
|
Back to top |
|
|
|