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

hardware question

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



Joined: 19 Jun 2007
Posts: 20
Location: Castelo Branco, Portugal

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

hardware question
PostPosted: Tue Mar 04, 2008 9:44 am     Reply with quote

Hello,
I have to connect several boards together, in a master/slave configuration. I will have one master and a total amount of 32 possible slaves. The maximum distance between master and slave is of 80 meters.

I was thinking on using a I2C bus with the 2 wires crossing all the slaves and with the slave address defined by hardware.
Am I going in the right direction?
Thank you
Guest








80 metre connection
PostPosted: Tue Mar 04, 2008 11:01 am     Reply with quote

You might consider RS-485 instead.Much better for the distance and noise immunity.Just as easy from the programming consideration.
Jay
JoaoSantos



Joined: 19 Jun 2007
Posts: 20
Location: Castelo Branco, Portugal

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

PostPosted: Tue Mar 04, 2008 11:12 am     Reply with quote

hello, thanks for the awnser.
I thougth of that, but can i share the RS485 connection? this is, can I use a bus shared by the 8 slaves without problems?
thanks
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 11:37 am     Reply with quote

have a look at http://www.rs485.com/rs485spec.html. You can have a maximum of 32 listening devices on the same line. By adding repeaters this can be extended to hundreds.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 11:41 am     Reply with quote

Quote:

I thougth of that, but can i share the RS485 connection? this is, can I use a bus shared by the 8 slaves without problems?

The RS-485 standard specifies up to 32 drivers and 32 receivers on a single (2-wire) bus.
The number can increase adding repeaters. We have systems running +180 MCU's simultaneously.


Humberto
Guest








PostPosted: Tue Mar 04, 2008 11:45 am     Reply with quote

Actually you can have up to 256 'lowpower' units online,though reality says you should 'break up' units into more manageable groups , especially if (WHEN) the communication wire breaks.

Jay
JoaoSantos



Joined: 19 Jun 2007
Posts: 20
Location: Castelo Branco, Portugal

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

PostPosted: Tue Mar 04, 2008 1:46 pm     Reply with quote

thank you all for your anwsers,

Just on (basic) doubt: the routines and protocol used in RS485, are the same of the RS232?
what i mean is: for the PIC point of view it's like i'm using RS232.
Thank you once more.
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 2:01 pm     Reply with quote

JoaoSantos wrote:
thank you all for your anwsers,

Just on (basic) doubt: the routines and protocol used in RS485, are the same of the RS232?
what i mean is: for the PIC point of view it's like i'm using RS232.
Thank you once more.


No, there is a fundamental difference in the fact that RS485 is a half-duplex communication with a transmit enable signal that needs to be controlled by anyone trying to transmit on the shared bus. Many people have run into problems trying to control this enable signal with the correct timing.

However you may just have to do it, because 80 meters is not appropriate for I2C.

Robert Scott
Real-Time Specialties
Guest








PostPosted: Tue Mar 04, 2008 2:04 pm     Reply with quote

Yes, except you have one pin controlling whether a PIC xmits or rcvs. I think there is an example either in the CCS manual or in the examples
files......

I use another form of long distance serial that is hackersafe and impervious to the 'cut-wire-syndrome' so other's who use RS485 can better help you out.

jay
JoaoSantos



Joined: 19 Jun 2007
Posts: 20
Location: Castelo Branco, Portugal

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

PostPosted: Tue Mar 04, 2008 3:00 pm     Reply with quote

thank you all. this discussion was a real eye openner.
I will take all of this into consideration, and decide what's best.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 3:00 pm     Reply with quote

Quote:

Just on (basic) doubt: the routines and protocol used in RS485, are the same of the RS232?
what i mean is: for the PIC point of view it's like i'm using RS232.


From the PIC point of view, handling RS485 is the same that handling RS232, except
the extra pin needed to handle the enable Tx/Rx of the transceiver. In most applications,
the pin #2 and #3 of the transceiver are wired together and are handled by the PIC pin
defined in the option "enable". Then let the compiler to do it's job.
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,enable=PIN_C5)

The standard doesn't mention anything regarding any special protocol. The main difference is in the physical layer and the way they drive the transmition lines, being RS232 a voltage controlled (+V/-V swing) and RS485 a differential current loop, being the last a high improvement in the common mode noise rejection. This feature is very important in data transmition lines running in severe electrical environments.


Humberto
JoaoSantos



Joined: 19 Jun 2007
Posts: 20
Location: Castelo Branco, Portugal

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

PostPosted: Tue Mar 04, 2008 5:00 pm     Reply with quote

Humberto wrote:
Quote:

Just on (basic) doubt: the routines and protocol used in RS485, are the same of the RS232?
what i mean is: for the PIC point of view it's like i'm using RS232.


From the PIC point of view, handling RS485 is the same that handling RS232, except
the extra pin needed to handle the enable Tx/Rx of the transceiver. In most applications,
the pin #2 and #3 of the transceiver are wired together and are handled by the PIC pin
defined in the option "enable". Then let the compiler to do it's job.
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,enable=PIN_C5)

The standard doesn't mention anything regarding any special protocol. The main difference is in the physical layer and the way they drive the transmition lines, being RS232 a voltage controlled (+V/-V swing) and RS485 a differential current loop, being the last a high improvement in the common mode noise rejection. This feature is very important in data transmition lines running in severe electrical environments.


Humberto

Thank you for another most usefull information.
But you lost me in the the pin #2 and #3 of the transceiver are wired together and are handled by the PIC pin
When you say transceiver you are refering to MAX483, for example?
I found this circuit , is it something
http://web.ukonline.co.uk/j.winpenny/pic/rs485.pdf

like this, or you are refering to something else?
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 6:57 pm     Reply with quote

[quote="Humberto"]
Quote:

...Then let the compiler to do it's job.
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,enable=PIN_C5)


I have never used the compiler's serial driver. I have always dealt directly with the PIC registers. So I am curious how the compiler "automatically" handles the enable signal. I have always found this to be the most difficult part of RS-485. It is easy to know when to turn it on - just before you start sending. But it is not so easy to know when to turn it off. You need to leave it on until the last character of a packet has completely shifted out of the PIC. This is not the same thing as the transmit holding register going empty, which causes an interrupt. The transmit holding register goes empty when it transfters its contents to the output shift register. But there is no interrupt telling you when the output shift register is done. There is a status bit that you can poll, but does that mean the compiler library function sits in a busy-loop polling to see when the output shift register goes empty?

Robert Scott
Real-Time Specialties
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 7:13 pm     Reply with quote

Here's the code for PCH vs. 4.069:
Code:

... #use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,enable=PIN_C5) 
0004:  BCF    TRISC.5
0006:  BSF    LATC.5     // Enable = high

0008:  BTFSS  PIR1.TXIF  // Wait for TXREG empty
000A:  BRA    0008

000C:  MOVFF  06,TXREG   // Put byte in TXREG
0010:  NOP   

0012:  BCF    TRISC.5
0014:  BSF    LATC.5       // Enable = high

0016:  BTFSS  TXSTA.TRMT   // Wait until byte is sent
0018:  BRA    0016

001A:  BCF    TRISC.5   
001C:  BCF    LATC.5   // Enable = low
001E:  GOTO   0048 (RETURN)

Quote:
#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,enable=PIN_C5)

//====================================
void main()
{

putc(0x55);

while(1);
}
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 7:58 pm     Reply with quote

Robert wrote:
Quote:

So I am curious how the compiler "automatically" handles the enable signal. I have always found this to be the most difficult part of RS-485.

Thanks to the code posted by PCM Programmer Very Happy you will see the code generated by CCS Compiler.
The "enable" option feature had been implemented in the first quarter of 2003 close-to PCM Version 3.136

Robert wrote:
Quote:

You need to leave it on until the last character of a packet has completely shifted out of the PIC.

It is self-answered looking in the .asm code generated.

JoaoSantos wrote:
Quote:

But you lost me in the the pin #2 and #3 of the transceiver are wired together and are handled by the PIC pin
When you say transceiver you are refering to MAX483, for example?

Yes the MAX483 is an RS485 transceiver. The oldest -and most popular- is the SN75176 made by National.
Most manufacturers have its own version.
Analog Devices: ADM2483
Linear Technology: LTC1685/6/7
Maxims: MAX3080/9 MAX3280 MAX3362 MAX3430/60/64/80 ,etc.
Texas Instruments: SN65HVD1176
SipexCorporation: SP481
Intersil: ISL41387
.........................

In the following thread you will find an interesting RS485 discution.

http://www.ccsinfo.com/forum/viewtopic.php?t=25720&highlight=rs485

Humberto
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