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 CCS Technical Support

[Help] UART processing with RS485

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



Joined: 25 Nov 2009
Posts: 27
Location: Vietnam

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

[Help] UART processing with RS485
PostPosted: Wed Jul 17, 2013 9:19 pm     Reply with quote

Dear all,
I'm using IEA-RS485 standard for my project.
I connected MASTER to 10 SLAVES.
These SLAVES respond to SERVER automatically based on their time-slot (100 milliseconds) after receiving request message from MASTER.

When MASTER send REQUEST to SLAVES,
SLAVE 1 respond after 100ms
SLAVE 2 respond after 200ms
....
SLAVE 10 respond after 1000ms

The problem is that, when one SLAVE sends a response, both other SLAVEs also receive that.
So how does SLAVE 1 refuse (deny) messages from SLAVE 2 to SLAVE 10?

Thanks,


Mr. Delfy
---------------------------------------------------------------
ISVC Lab. KAIST, Daejon, South Korea Rolling Eyes
_________________
-------------------------------------------------
Mechatronics Department, Coltech, VNUH
Hanoi, Vietnam.
-------------------------------------------------


Last edited by Delfy_Coltech on Thu Jul 18, 2013 8:51 am; edited 1 time in total
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Thu Jul 18, 2013 12:29 am     Reply with quote

Each slave should have a different address and only respond to their address. Read up on the RS485 specifications.

Regards
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Thu Jul 18, 2013 8:50 am     Reply with quote

You need to have the master do something that uniquely identifies itself, and program the slaves so this action is the only thing that they'll use to reset their clocks.

One possibility would be to have the master send a Break character, which some PIC processors can do by setting a flag in one of the registers--I think it's 13 low bits sent by the UART. I don't know if CCS has a command to do this or if you'd have to figure it out for yourself.

Another idea is to make the data up into packets, with some unique protocol to identify the start of a packet and some way to identify the sender or intended recipient or both. Then you could have the slaves recognize packets from the master to reset the clock, but reject packets from any other slave.
Delfy_Coltech



Joined: 25 Nov 2009
Posts: 27
Location: Vietnam

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

PostPosted: Thu Jul 18, 2013 8:50 am     Reply with quote

Very Happy Hi alan,
It's certainly, I have set the ID for every SLAVE!
But we use only one data bus (line), so all slaves will receive data from another...

Any ideas?
_________________
-------------------------------------------------
Mechatronics Department, Coltech, VNUH
Hanoi, Vietnam.
-------------------------------------------------
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Thu Jul 18, 2013 9:04 am     Reply with quote

Some UART's allow an address to be programmed and will then only receive if the address match and usually uses a 9-bit protocol.

If software the slaves will receive the data but should ignore it if a valid address has not been received. You have to live with this overhead in the software.

Regards
Alan
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Jul 18, 2013 9:04 am     Reply with quote

Hi,

You mean to tell us that you've got all the communications and timing figured out, but you can't solve this issue? That seems hard to understand!

I have a 'multi-drop' RS-485 network that sends commands to the slaves using this protocol:

Code:

#Nxx:Q<CR>      <----- Query Command     - Response is !Nxx:Q0,0:00000<CR>


Note that the Master to Slave commands are prefaced with a '#', followed by a unique node number, and the replies, Slave to Master are prefaced with a '!'. So, all Slaves 'see' all Master commands, but only respond when the correct '#', and correct node address is received. All the slaves also see all the slave responses, but ignore them because they don't start with a '#'.

John
Delfy_Coltech



Joined: 25 Nov 2009
Posts: 27
Location: Vietnam

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

PostPosted: Thu Jul 18, 2013 9:16 am     Reply with quote

Dear Mr ezflyr!

I know that!
But it still waste a few time to receive all slave respond and then we must check to ignore!

Any better idea? or we must use that way? Receive all then check and ignore...
_________________
-------------------------------------------------
Mechatronics Department, Coltech, VNUH
Hanoi, Vietnam.
-------------------------------------------------
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jul 18, 2013 9:33 am     Reply with quote

That's one of the problems with half-duplex communications, every slave has to decide 'is it for me ?' John's way is simple and fast. Depending on distance you can easily get 115K200 baud which is a bit faster than the 24baud I've used in the past. As you're delaying 100-1000ms, the 'parsing' time (is it for me?) is not a real factor in the overall picture.

There are other hardware options, like full duplex, or VVSI but RS485 is a defacto standard nowadays for multidrop communications.

hth
jay
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Jul 18, 2013 11:02 am     Reply with quote

Hi,

You could 'synchronize' the network each second with a general query command sent to all slaves. Then each node would disable its UART
(setup_uart(0)) until it's 'timeslot' for sending. All UARTs would then come back on to listen for the next 'Sync' command. It shouldn't be too
hard to code!

John
Delfy_Coltech



Joined: 25 Nov 2009
Posts: 27
Location: Vietnam

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

PostPosted: Thu Jul 18, 2013 8:01 pm     Reply with quote

Dear all,
thanks for all comments of you!
Finally, in this case, there are two way:
1. Accept to receive all slave messages and then check to ignore unnecessary message
2. On/Off UART (or enable/disable RDA interrupt) in each SYNC time

Thanks,
_________________
-------------------------------------------------
Mechatronics Department, Coltech, VNUH
Hanoi, Vietnam.
-------------------------------------------------
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

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

RE
PostPosted: Thu Jul 18, 2013 11:42 pm     Reply with quote

Use a 'token packet' that gives permission to a slave to transmit and respond for a certain time period, after the elapse of the time period the token can be given to the next slave, the master server would have to ensure the token is passed around correctly and also to skip a slave in case it is unable to respond.

In any case you need unique addresses for each slave.

You do not have to disable the RDA interrupt, the packet handler in your RS485 driver should be able to filter out irrelevant messages.

thanks
a
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