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

Serial communication

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



Joined: 06 May 2008
Posts: 14

View user's profile Send private message

Serial communication
PostPosted: Thu May 08, 2008 1:57 am     Reply with quote

I am using 4 microcontrollers for serial communication. 1 as master and remaining are slaves. communication work fine but on polling address from slaves , master does not recieve complete address from slave but increment number of slaves correctly.

There might be some collision between master and slave.

How can i get address from slave while polling from master and use printf in master to print slave address on terminal.
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Serial communication
PostPosted: Thu May 08, 2008 4:09 am     Reply with quote

If there is a possibility of collisions between the master and the slaves, then you need to change the design of your protocol to eliminate that possibility. Also you didn't say what kind of electrical connection you are using. Normal RS-232 serial is not designed for more than one transmitter on each line. RS-485 serial is designed for multiple nodes, but it requires the control of a "transmit enable" on the transmit buffers. Or you could use your own design with an "open collector" type of driver. This will allow multiple transmitters without needing an enable signal (like the RS-485), but it still needs a protocol that avoids collisions, and it is limited in baudrate because of the passive pull-up used in open-collector design.

Robert Scott
Real-Time Specialties
Guest








PostPosted: Thu May 08, 2008 4:18 am     Reply with quote

i m using RS485 protocol
Ttelmah
Guest







PostPosted: Thu May 08, 2008 9:36 am     Reply with quote

No.....
RS485, is a _signalling standard_.
You then use a 'protocol' to talk over this.
The key is that your _protocol_ has to be designed to sense/deal with/avoid collisions. So (for instance), you have ones where the bus is taken 'busy', then released, and tested to see if it does go idle. If not, then something else is 'on the bus'. This requires great care in timing, so that two devices can't release at the same time. Or you have systems with separate 'select' lines. Or you monitor your own data transmission, and use a random 'retry', permuted with the device address.
The first is a common solution, and (for example), if there are not too many devices, and each has a unique address over a small range (like 1...16), you can use the approach, of testing for the line being idle over a short period, then 'seizing' the line, and then releasing after your address number of time periods. Since no other device can have the same address, and another device could only have seized within a very few uSec of this device (however long it takes to go from 'test' to 'seize'), you can tell whether you have the bus, by whether it releases or not. Also, if you make 'higher addresses have higher priority', you know if it is still held high, that the other device _is_ a higher priority device.

Best Wishes
Humberto



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

View user's profile Send private message

PostPosted: Thu May 08, 2008 9:51 am     Reply with quote

Quote:

i m using RS485 protocol

RS485 do not have a defined protocol, it only refers to the hardware layer.

Quote:

There might be some collision between master and slave.

RS485 do not have any built in avoidance collision. For sure you will need to re-check the used code.

The most simple protocol should follows these minimum rules:
1) The Master initiate ALL the transactions while the Slaves are listening.
2) ALL the transactions should have an ID Address.
3) After an enquire, the Master must release the line and keep in idle mode until the Slave reply.
4) The Slaves gain access to the Tx line ONLY to reply a Master inquiry.

Knowing the time involved in each transaction and following the preceding minimum rules,
there is not chance for any data collision.

Humberto

1)EDITED: Sorry Ttelmah I didn't see your post when I start answering.
Ttelmah
Guest







PostPosted: Thu May 08, 2008 2:16 pm     Reply with quote

I was probably typing it at the same time. Smile
Semi-simultaneous answers are sometimes quite common, and often have different 'slants' on the same problem. We seemed remarkably close to the same 'angle'!...

Best Wishes
ashrafkhatri



Joined: 06 May 2008
Posts: 14

View user's profile Send private message

PostPosted: Fri May 09, 2008 12:36 am     Reply with quote

Thanks for your time

Mr. Humberto following is the one possible condition for serial communication.

1) The Master initiate ALL the transactions while the Slaves are listening.
2) ALL the transactions should have an ID Address.
3) After an enquire, the Master must release the line and keep in idle mode until the Slave reply.
4) The Slaves gain access to the Tx line ONLY to reply a Master inquiry.

For above situation i need to program slaves accordingly. wait from finish master character and then respond on different time as per slave address. Mean different time for each slave for each different address.
A good approach to do it, and i will do it if i could not do it as i want to do.

I do it differently , I am sending address from 01 to 32 slaves.
when i send 01 to slaves from master, the 01 address slave should respond to master. before send an address 02 to second slave. Is it possible ?
Humberto



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

View user's profile Send private message

PostPosted: Fri May 09, 2008 12:06 pm     Reply with quote

I do not know exactly what do you want to do. What I said is only a general rule
regarding how to define a very primitive protocol in order to avoid collisions.
There is not any protocol that will be used for all the situations. Happily one expect
that the programmer knows the needed step by step procedures involved to overcome it.

Quote:

wait from finish master character and then respond on different time as per slave address. Mean different time for each slave for each different address.

This is not the best way to do it.
After the Master sent the string, the addressed Slave should respond in the next time
slot reserved for this, it doesn't matter which address it have.


Humberto
foodwatch



Joined: 18 Apr 2006
Posts: 66

View user's profile Send private message Yahoo Messenger

PostPosted: Fri May 09, 2008 2:44 pm     Reply with quote

I do this everyday using RS485. Once per second the master enables the transmit line and DISABLES the receive side so as not to fill the master's buffer with its own transmitted data. I send a start of transmission byte and an address byte and endo of transmission byte and wait for a finite window for an answer by switching to receive enable on the master. I then repeat to each slave. This depends on how long your slaves transmission is. But you might find the pic is hearing its own transmissions if you have the rx and tx enable lines tied together and you are using a 2 wire circuit. I send data in ascii hex so the start and end bytes never occur in the data packets. This makes it easier to determine end of transmission with varied packet lengths from your slaves.
Humberto



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

View user's profile Send private message

PostPosted: Fri May 09, 2008 3:34 pm     Reply with quote

foodwatch wrote:
Quote:

But you might find the pic is hearing its own transmissions if you have the rx and tx enable lines tied together and you are using a 2 wire circuit.

NOP, this is wrong.

From the SN75176 Datasheet:
http://focus.ti.com/lit/ds/symlink/sn75176a.pdf
"The driver and receiver have active-high and active-low enables, respectively,
that can be externally connected together to function as a direction control."



Humberto
foodwatch



Joined: 18 Apr 2006
Posts: 66

View user's profile Send private message Yahoo Messenger

PostPosted: Fri May 09, 2008 4:15 pm     Reply with quote

Tie them together if you wish, but you have more control if you control them separately (but usually at the same time). The MAX1487 is much better, draws much less current, is pin compatible and has much better static protection.
Humberto



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

View user's profile Send private message

PostPosted: Fri May 09, 2008 5:41 pm     Reply with quote

If one transceiver is better than other or if it draws less current or not, it is not the discussing
point in this thread. I only remarked one phrase of your post were I found a miss understood
concept. Then I got the datasheet, copied and pasted the right way just to show clearly the concept.

Humberto
ashrafkhatri



Joined: 06 May 2008
Posts: 14

View user's profile Send private message

PostPosted: Fri May 09, 2008 11:56 pm     Reply with quote

Quote:

After the Master sent the string, the addressed Slave should respond in the next time
slot reserved for this, it doesn't matter which address it have.


Chance of data collision If all slaves(i.e. 1 to 16) respond on a same time slot reserve for them?
Humberto



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

View user's profile Send private message

PostPosted: Sat May 10, 2008 9:00 am     Reply with quote

You are missing the point 4:
Quote:

4) The Slaves gain access to the Tx line ONLY to reply a Master inquiry.

Taking care of this, by no way more than one Slave can reply in the same time.

In a Master/Slave architecture -as you propose- one Master can talk to thousands of
Slaves who are normally listening, but ONLY ONE Slave can reply to the Master in the
expected/reserved slot time. Normally the Slave who respond is the one who was addressed.
Even the most popular communications protocol like FTP -used in Internet- implements
addressing for large set of complex protocols but always between 2 devices (client/server)
at the same time, after it was granted to access.


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