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

problem with rs485 1 master 2 slave
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
talamahahahe



Joined: 15 Feb 2015
Posts: 39

View user's profile Send private message

problem with rs485 1 master 2 slave
PostPosted: Sun Jul 19, 2015 10:21 am     Reply with quote

i was communicate rs485, transfer data between 2 pic 16f887 ok (1 master and 1 slave) but now when i use 1 pic master 2 pic slave i can't send data to both of slave.

i use ccs 5.048

this is code for master

Code:

#include <16f887.h>
#fuses HS,NOWDT,PUT,NOLVP,NOPROTECT
#use delay(clock=16M)
#include <flex_lcd.c>
#include <rs485.c>
unsigned int data1[16]={"Test slave 1"};
unsigned int data2[16]={"Test slave 2"};

void main()
{
   lcd_init();
   rs485_init();
   rs485_send_message(0x11,16,data1);
   rs485_send_message(0x12,16,data2);
   while(true)
   {
     
   }
}


This is code for slave1
Code:

#include <16f887.h>
#fuses hs,nowdt,noprotect
#use delay(clock=16M)
#include <flex_lcd.c>
#define RS485_ID  0x11
#include <rs485.c>
unsigned int data[16];


void main()
{
   lcd_init();
   rs485_init();
   while(true)
   {
      rs485_get_message(data, false);
     
      lcd_gotoxy(1,1);
      printf(lcd_putc,"%s",data);
     
   }
}


this is code for slave 2
Code:

#include <16f887.h>
#fuses hs,nowdt,noprotect
#use delay(clock=16M)
#include <flex_lcd.c>
#define RS485_ID  0x12
#include <rs485.c>
unsigned int data[16];

void main()
{
   lcd_init();
   rs485_init();
   while(true)
   {
      rs485_get_message(data, false);
      lcd_gotoxy(1,1);
      printf(lcd_putc,"%s",data);
   }
}


in code master, if i just send for slave 1 or slave 2, it is ok, but when i send for all of 2 slave, 2 slave seem not receive data. i was use interrupts RDA for slave to get data but it worse than
Ttelmah



Joined: 11 Mar 2010
Posts: 19451

View user's profile Send private message

PostPosted: Sun Jul 19, 2015 1:04 pm     Reply with quote

Describe accurately (or post a drawing), of the RS485 connections.

Wires to PIC.
Which pin on the driver chip connects to which pin on the PIC's.
What bus termination you have?.
What bus biasing you have?.
What pins from each driver connects to the other?.
temtronic



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

View user's profile Send private message

PostPosted: Mon Jul 20, 2015 5:52 am     Reply with quote

tips.
1) put a delay_ms(500); before the lcd_init(); call. This will allow the LCD module to properly powerup before you access it.

2) In the 'master' program put a delay after sending each message. Though I haven't looked at the 485 driver, it may need some 'time' between each sending to the slaves.

3) In the 'master' pgm, I'd put a 'local LCD' confirm that you do send the msgs,at least for test purposes.

Since you say it works for either slave 11x or 12x but not both, I suspect it's a 'timing' issue (software) and not hardware(unless you have to move wires)

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19451

View user's profile Send private message

PostPosted: Mon Jul 20, 2015 7:22 am     Reply with quote

I think he is not controlling the RS485 direction properly.

So the slaves don't deselect. This wouldn't 'matter' for one slave, but for multiple.....
talamahahahe



Joined: 15 Feb 2015
Posts: 39

View user's profile Send private message

PostPosted: Tue Jul 21, 2015 7:02 am     Reply with quote

i am sorry to reply late, i was busy at school few day. This is schematic i simulate in proteus 8.1 . Maybe it conflict in vie because i see in proteus , some signal pin of lcd have yellow not red or blue. i don't know i wrong hardware or software.



i was try on delay_ms(100) after send message, but it doesn't work too,

this is all of my simple project, please help me

Code:

#include <16f887.h>
#fuses HS,NOWDT,PUT,NOLVP,NOPROTECT
#use delay(clock=16M)
#include <flex_lcd.c>
#include <rs485.c>
unsigned int data1[16]={"Test slave 1"};
unsigned int data2[16]={"Test slave 2"};

void main()
{
   delay_ms(500);
   lcd_init();
   rs485_init();
   rs485_send_message(0x11,16,data1);delay_ms(100);
   rs485_send_message(0x12,16,data2);delay_ms(100);
   while(true)
   {
     
   }
}
talamahahahe



Joined: 15 Feb 2015
Posts: 39

View user's profile Send private message

PostPosted: Tue Jul 21, 2015 7:16 am     Reply with quote

ex_rs485.c in example just have communicate rs485 with pic and computer. Do you have sample code communicate 1 pic master and 2 pic slave, maybe i will understand clearly if i read sample code
temtronic



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

View user's profile Send private message

PostPosted: Tue Jul 21, 2015 7:49 am     Reply with quote

Have to ask are you using REAL hardware ?
The schematic you show from Proteus will NEVER work in the REAL World.
You require proper RS485 termination resistors( pullup,bias,pulldown).

There are several 'threads' about this ,as well, just google RS485 to get a site with the specs, or just download the datasheet for the RS485 transceivers ( which are NOT in the 'schematic' !!).

Jay
talamahahahe



Joined: 15 Feb 2015
Posts: 39

View user's profile Send private message

PostPosted: Tue Jul 21, 2015 8:27 am     Reply with quote

i just test in proteus ,when it simulate ok, i will do real board, just 1 thing, master just can send data to slave 1 or slave 2 , can't send for 2 slave simultaneously. i was do every thing to do that but failure

this is schematic i use max487 to communicate rs485, either slave 1 receive data or slave 2 receive data, can't both of them



with master code
Code:

#include <16f887.h>
#fuses HS,NOWDT,PUT,NOLVP,NOPROTECT
#use delay(clock=16M)
#include <flex_lcd.c>
#include <rs485.c>
unsigned int data1[16]={"Test slave 1"};
unsigned int data2[16]={"Test slave 2"};

void main()
{
   lcd_init();
   rs485_init();
   while(true)
   {
      rs485_send_message(0x11,16,data1);
      rs485_send_message(0x12,16,data2);
   }
}


slave 1 code
Code:

#include <16f887.h>
#fuses hs,nowdt,noprotect
#use delay(crystal=16M)
#include <flex_lcd.c>
#define RS485_ID  0x11
#include <rs485.c>
unsigned int data[16];

void main()
{
   lcd_init();
   rs485_init();
   while(true)
   {
      rs485_get_message(data, false);
      lcd_gotoxy(1,1);
      printf(lcd_putc,"%s",data);
     
   }
}


slave 2 code
Code:

#include <16f887.h>
#fuses hs,nowdt,noprotect
#use delay(crystal=16M)
#include <flex_lcd.c>
#define RS485_ID  0x12
#include <rs485.c>
unsigned int data[16];

void main()
{
   lcd_init();
   rs485_init();
   while(true)
   {
      rs485_get_message(data, false);
      lcd_gotoxy(1,1);
      printf(lcd_putc,"%s",data);
   }
}
temtronic



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

View user's profile Send private message

PostPosted: Tue Jul 21, 2015 10:42 am     Reply with quote

You need to read and study RS485 design. The MAX487 datasheet would be a good start.
ie: you need ONE set of 'termination' resistors consisting of a pullup from Vcc to 'A', a bias from 'A' to 'B' and a pulldown from 'B' to ground.
Your schematic doesn't show the pullup and there are too many bias and pulldown resistors.
also normally to tie DE and _RE together and connect to the 'control' pin as designated in the #use RS232...options.....). Just see the example CCS supplies in the examples folder.


Jay
talamahahahe



Joined: 15 Feb 2015
Posts: 39

View user's profile Send private message

PostPosted: Tue Jul 21, 2015 11:26 am     Reply with quote

i was use pullup up A to VCC like this. But it now both of 2 lcd show nothing. :( i don't know what problem



both of slave is not working.

But one thing is very stranger when i not use resistor pull up at A point

first, slave 1 will receive data immediately, and after long time , slave 2 receive data (i wait about 1 hour). what problem with it ??
temtronic



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

View user's profile Send private message

PostPosted: Tue Jul 21, 2015 2:06 pm     Reply with quote

Are you using real Pics or just ISIS ??

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19451

View user's profile Send private message

PostPosted: Tue Jul 21, 2015 2:23 pm     Reply with quote

There also _must_ be a pullup resistor on the line from RD to RX. Otherwise when the bus is being driven, the PIC will receive garbage.
drolleman



Joined: 03 Feb 2011
Posts: 116

View user's profile Send private message

PostPosted: Tue Jul 21, 2015 5:17 pm     Reply with quote

Why are you dealing with this guy. Proteus doesn't work. Point to the top of the forum, and shut the thread down. This will stop others from trying to do the same. Your talents (amazed by them) are better spent on issues where people are putting the effort.
talamahahahe



Joined: 15 Feb 2015
Posts: 39

View user's profile Send private message

PostPosted: Tue Jul 21, 2015 10:53 pm     Reply with quote

i don't know which hardware is true so i just simulate on proteus and then ,if everything ok, i will do in real board, can you give me your true hardware, the way you connect pic and max487
Ttelmah



Joined: 11 Mar 2010
Posts: 19451

View user's profile Send private message

PostPosted: Wed Jul 22, 2015 1:14 am     Reply with quote

1) The first thing to understand, is that Proteus/Isis, is badly flawed when dealing with PIC's. You can put designs into this that refuse to work, yet will run fine in a real chip. You can put designs into this that it says 'yes this works', which do not have a hope of running in a real chip.
Time spent using the Proteus simulator with PIC's, is time wasted. The quicker you understand this, the quicker your designs will start to work....

2) Then the second thing is the 485 bus itself.

This requires two separate things.

First termination. The bus wants to be _linear_. Running from one device at an end, along past other devices (with short 'stub' connections to these - no more than a couple of inches long), and ending with another end device. Each _end_ device needs termination, nowhere else. A lot of commercial systems use a 'through' connector at each device along the bus, and then you plug a terminator into the unused connections at each end. There should be just two terminators.

Then bias. The bus wants bias at just _one_ point. Again the devices with the plug in terminators usually have a jumper/switch on these to enable the bias. You have to be very careful about the direction of the bias. Unfortunately different manufacturers use different names for the bus lines. The standard is the Maxim way, with line 'A' being the un-inverted line, and line 'B' being the inverted line. With this, line A wants to be drawn +ve, and line B -ve. However if using any other make of transceiver, make sure that it is the un-inverted line that is taken +ve. Even better, use transceivers that do not require bias.

The setup should be:

First 'bias' terminator. 750R to +5v. Line A. 150R to line B. 750R to 0v.
The bias resistors are seen as across the impedance matching resistor, so this has to increase on the terminator with the bias, or a mismatch will occur.

Then the bus......

The at the other end, the second 'non-bias' terminator. 120R between Line A and Line B only.

This is for a cable of 120R impedance.

As drawn at the moment, your bus has much too much bias, and too many terminators.

3) Then the final thing is driver and it's connections to the PIC.

RO to PIC RX. _With a 4K7 pull up resistor to 5v_.
This resistor is essential. Without it, when the receiver is disabled, the PIC _will_ see random data. Uurgh.

DI to PIC TX.

Then there are two options. Separate control of DE and RE (pointless in this application), or combined control of these.

For combined control, connect RE on the driver to DE, and this single connection to a pin on the PIC.

Then setup the driver with:
Code:

#define RS485_ID xx //define this to the ID you want for each slave
//before the driver is loaded.

#define RS485_RX_ENABLE //define this as [u]blank[/u], for combined control
#define RS485_ENABLE_PIN PIN_xx //whatever pin you connect to RE/DE
#define RS485_USE_EXT_INT FALSE //to use the hardware UART

#include <rs485.c>


Build yourself a circuit. Verify each PIC works _on it's own_ first.
Then connect as listed, and RS485 should work.

The only time 'combined control' of the buffer is not used, is when the driver is written to monitor the data it itself is sending and report an error if the bus is shorted or ringing. The existing code does not do this, so combined control is easier and saves a PIC pin.

Starting with Proteus/Isis, is equivalent to starting a marathon, by nailing your feet to the floor. Don't do it.....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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