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

RS485 communication between 1 master (PC) and 3 slave

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



Joined: 12 Apr 2011
Posts: 7

View user's profile Send private message

RS485 communication between 1 master (PC) and 3 slave
PostPosted: Tue Apr 12, 2011 2:41 pm     Reply with quote

hi, I'm new in embedded c and I have to establish a communication between 3 slave (pic16F877) and 1 master (PC) via RS485. The problem that I try so much solution from this forum and no one is working for me:

http://img34.imageshack.us/i/sheman.png/

I'm now working just for receive information from rs232 and transmit with RS485 just to 1 pic.

My project is to send information to 3 pic and with address and the one with rue address only get information and reply to master.

* sorry for my bad english
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

Re: RS485 communication between 1 master (PC) and 3 slave
PostPosted: Tue Apr 12, 2011 3:08 pm     Reply with quote

helmi03 wrote:
hi, I'm new in embedded c and I have to establish a communication between 3 slave (pic16F877) and 1 master (PC) via RS485. The problem that I try so much solution from this forum and no one is working for me:

http://img34.imageshack.us/i/sheman.png/

I'm now working just for receive information from rs232 and transmit with RS485 just to 1 pic.

My project is to send information to 3 pic and with address and the one with rue address only get information and reply to master.

* sorry for my bad english

Hi helmi03,

Well, I won't do work FOR you but I might be able to assist you or direct you into the right direction. You're wondering how to communicate with rs 232. Check #USE RS232 in the CCS manual. You also wanna look at functions like fputc(), fgetc(), printf() or kbhit(). You might also wanna look at the example ex_RS232_485.c in the examples directory
ezflyr



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

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 3:12 pm     Reply with quote

Hi,

This is a pretty easy project actually. What you want is a Master-Slave half-duplex arrangement, ie. nobody "talks" on the bus except the Master, unless asked to do so.

You need to design a simple command protocol that the Master will use to communicate with the Slaves. You can make your life much easier by doing this intelligently. In the past I've used something like this:

#SLVX:CMD<Cr>, where 'X' is the address 1, 2, or 3. The important parts here are the Start Character '#', and the End Character 'Cr' - your receive routines will use them to know when a command string starts and ends.

Your picture was too small even when enlarged, but it appears that you are using the RS485 transceiver incorrectly. Pins 2 and 3 can be tied together, and then controlled by a digital output on the PIC. This allows you to control the direction of data on the bus. The #USE RS232 statement can be configured to include the direction control automatically.

Oh, is this exclusively a Proteus project, or will you also do this in real hardware?

John
helmi03



Joined: 12 Apr 2011
Posts: 7

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 3:22 pm     Reply with quote

thank you for answer me, i will try this for real .


@cerr i try so much code but no one is working correctly for me. example :

Code:

#include <C:\Program Files\PICC\Devices\16F877.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP
#use    delay(clock=10000000)
#use rs232(baud=9600,xmit=PIN_C6, rcv=PIN_C7, stream=PC)


#define RS485_RX_BUFFER_SIZE 64
#define RS485_USE_EXT_INT FALSE
#define  RS485_ID             0x09
#define  ADAPTER_RS485_ID  0x7f
 
#define RS485_RX_ENABLE    PIN_B5
 #define RS485_ENABLE_PIN   PIN_B4
#define RS485_TX_PIN       PIN_C6
#define RS485_RX_PIN       PIN_C7

#include <C:\Program Files\PICC\Drivers\rs485.c>
#include <C:\Program Files\PICC\Drivers\stdlib.h>
int8 msg[32];
char RS485getc() {
   rs485_get_message(msg, TRUE);
   return msg[2];
}
 
char h;
void main()
{

output_low(RS485_RX_ENABLE);
   set_tris_a(0x00);
   
   output_low(RS485_ENABLE_PIN); 
      rs485_init();
   while(true)   
   {
   h=RS485getc();
      output_a('h');
   }
}


and try so much other code i just won't to send a number and this number will be display in the 7seg.

i tried the ex RS485-232 but i think i didn't use it correctly.


can some one please explain to me what this function do


fputc() to write in output

fgetc() to read

, printf() ??

or kbhit() ??

Thank you
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 3:25 pm     Reply with quote

helmi03 wrote:



can some one please explain to me what this function do


fputc() to write in output

fgetc() to read

, printf() ??

or kbhit() ??

Thank you

I would suggest you look at the manual. That should help you!
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 7:11 pm     Reply with quote

you also want to look closer at #USE RS232 in the manual and it's option ENABLE which will do an RS485 enable for you.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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