CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

About RS485 9th bit

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Gabriel Caffese



Joined: 09 Oct 2003
Posts: 39
Location: LA PLATA, ARGENTINA

View user's profile Send private message Visit poster's website MSN Messenger

About RS485 9th bit
PostPosted: Fri Jan 14, 2005 12:45 pm     Reply with quote

Hello everyone,

I want to use the 9th bit option the " #use rs232 " command has.
My rs485 network, has 1 master and 16 slaves.
I will use the 9th bit for addressing one device in particular, and all devices will hear and detect it, but can not find the way to do this. There is no example about this 9th bit option. There is one example on RS485 communication, but none about this topic.

Has anyone done such a thing before, and could help me ?

Thanks in advance,

Gabriel.-
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Jan 14, 2005 1:07 pm     Reply with quote

Basically you setup for 9 bit data. The nineth bit is set for addresses and clear for data. In your receive interrupt, check the nineth data bit. If it is set, see if the data matches the device address. If not, you can ignore the rest of the data until you see the nineth bit set again. I like to set up the registers myself. So I would read the section in the datasheet to set things up.
Gabriel Caffese



Joined: 09 Oct 2003
Posts: 39
Location: LA PLATA, ARGENTINA

View user's profile Send private message Visit poster's website MSN Messenger

PostPosted: Fri Jan 14, 2005 9:47 pm     Reply with quote

Mark,

I´ve already done what you say, but can not get a clue.
The problem is that I can not detect the 9th bit.
Does anyone have sample code for helping me ?

Thanks.-
Ttelmah
Guest







PostPosted: Sat Jan 15, 2005 3:15 am     Reply with quote

Gabriel Caffese wrote:
Mark,

I´ve already done what you say, but can not get a clue.
The problem is that I can not detect the 9th bit.
Does anyone have sample code for helping me ?

Thanks.-

If you want to access the ninth bit directly in CCS, without talking to the registers, then use:
#bit ninth_bit = RS232_ERRORS.7

This then allows you to set the bit, and retrieve the bit when needed. So when a character is received, if you read 'ninth_bit', it will contain the bit received. If you write to 'ninth_bit', and then send a character, the value you wrote, gets sent as the ninth bit.

Best Wishes
Gabriel Caffese



Joined: 09 Oct 2003
Posts: 39
Location: LA PLATA, ARGENTINA

View user's profile Send private message Visit poster's website MSN Messenger

PostPosted: Sat Jan 15, 2005 2:31 pm     Reply with quote

Ttelmah,

At RCSTA.0, I could get that 9th bit I´m looking for (but never appears).
I´m using the hardware UART, so at RS232_ERRORS, there is a copy of RCSTA (except bit 0, wich is used to indicate a parity error).
So, having a hardware UART, I loose that 9th bit (if reading RS232_ERRORS).
If I directly check the RCSTA register, I always see it in 0.

In resume, has anyone managed to use this 9th bit option ???
If so, could you post an example ??

Thanks to everone who helped.

Gabriel.-
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sat Jan 15, 2005 2:47 pm     Reply with quote

Post a small sample test program. One for the send and one for the receive.
Thomas Blake



Joined: 18 Jan 2004
Posts: 22
Location: Burbank CA

View user's profile Send private message

9th bit
PostPosted: Mon Jan 17, 2005 11:54 am     Reply with quote

I've used the 9th bit for RS-485 using the PIC16F873:

#BYTE rcsta_copy = 0x0018
#BIT rx_bit_9 = rcsta_copy.0

Originally I did have a problem with using the 16F873.h file macros with PCM 3.092, so I manually put in the #BYTE directive with the RCSTA address. You don't say which chip you're using, but try forcing the assignment like that.
Gabriel Caffese



Joined: 09 Oct 2003
Posts: 39
Location: LA PLATA, ARGENTINA

View user's profile Send private message Visit poster's website MSN Messenger

PostPosted: Mon Jan 17, 2005 4:20 pm     Reply with quote

Thomas,

Thank you very much for replying. I have just solved the problem. It was a PC-software problem -the master- wich was not checked by me.
Now I have done software in Turbo Pascal and everything works ok.

Gabriel.-
Ttelmah
Guest







PostPosted: Tue Jan 18, 2005 3:12 am     Reply with quote

The number of problems with PC communication, caused by things like the MSComm control, is 'legion'...
Glad it is working now.

Best Wishes
Goldfrapp
Guest







Neither can I...........
PostPosted: Thu Jan 20, 2005 9:58 pm     Reply with quote

I have the same problem: Can´t get ninth bit over RS485 !!!!!
For those who solved it: could you post same code, please ?
I transmit from PC, and check with a logic analyzer: From PC side, everything is ok.
When receiving from 16F87, I never ever get this ninth bit !!!!

HELP !
Guest








PostPosted: Fri Jan 21, 2005 7:58 am     Reply with quote

Ooops !
I have the same problem. Help me too !!!!
David Lynch
Guest







PostPosted: Fri Jan 21, 2005 7:37 pm     Reply with quote

It seems noone really knows about this.
Maybe would be better to visit the Piclist. Think you should.

David
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Fri Jan 21, 2005 8:50 pm     Reply with quote

David Lynch wrote:
It seems noone really knows about this.
Maybe would be better to visit the Piclist. Think you should.

David


RJ answered the question above very well with

#bit ninth_bit = RS232_ERRORS.7

If your compiler does not support this you can create your own version of RS232_ERRORS with the #byte command at the datasheet for your part, specifically the section on its hardware UART.

If you are trying to do 9-bit transfers with the software UART generated by the CCS compiler, you are going to have problems. Better in this case to write your own software UART if your chip doesn't have a hardware UART.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
David Lynch
Guest







PostPosted: Sat Jan 22, 2005 6:42 am     Reply with quote

rwyoung,

Think you´re wrong. RS232_ERRORS.7 is only used with software uart. It´s easy that way. Have not heard of anyone that could solve the hardware uart problem.

David.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sat Jan 22, 2005 8:58 am     Reply with quote

From the datasheet:
Quote:

RCSTA: RECEIVE STATUS AND CONTROL REGISTER (ADDRESS 18h)
bit 7 SPEN: Serial Port Enable bit
1 = Serial port enabled (configures RC7/RX/DT and RC6/TX/CK pins as serial port pins)
0 = Serial port disabled
bit 6 RX9: 9-bit Receive Enable bit
1 = Selects 9-bit reception
0 = Selects 8-bit reception
bit 5 SREN: Single Receive Enable bit
Asynchronous mode:
Don’t care
Synchronous mode - master:
1 = Enables single receive
0 = Disables single receive
This bit is cleared after reception is complete.
Synchronous mode - slave:
Don’t care
bit 4 CREN: Continuous Receive Enable bit
Asynchronous mode:
1 = Enables continuous receive
0 = Disables continuous receive
Synchronous mode:
1 = Enables continuous receive until enable bit CREN is cleared (CREN overrides SREN)
0 = Disables continuous receive
bit 3 ADDEN: Address Detect Enable bit
Asynchronous mode 9-bit (RX9 = 1):
1 = Enables address detection, enables interrupt and load of the receive buffer when RSR<8> is set
0 = Disables address detection, all bytes are received, and ninth bit can be used as parity bit
bit 2 FERR: Framing Error bit
1 = Framing error (can be updated by reading RCREG register and receive next valid byte)
0 = No framing error
bit 1 OERR: Overrun Error bit
1 = Overrun error (can be cleared by clearing bit CREN)
0 = No overrun error
bit 0 RX9D: 9th bit of Received Data (can be parity bit, but must be calculated by user firmware)


Bit 0 of the RCSTA is the nineth bit. If you are having problems, then read the datasheet. Quit using the ERRORs variable and do it yourself. And as far as
Quote:
Have not heard of anyone that could solve the hardware uart problem.
I can Very Happy Works just fine when you read and understand the datasheet.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group