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

RS-485 synchronism method

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



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

RS-485 synchronism method
PostPosted: Fri Feb 22, 2008 6:06 am     Reply with quote

Hi there. I´ve got a project that is working with a RS-485 communications interface.I´ve got one master device controling all the other slaves with an im alive status in each 100ms. My problem is that if i stop communications for at least one day without working it takes several time to start work. For an example today it took 2 min for the slave to start responding. So i believe that the problem might be in the hardware or software in both devices (master or slave). The question is why does it take so much to responde the first status and then after that it works for hours. Do i need any synchronism method to insure that the first question is awnsered?? Thanks...
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: RS-485 synchronism method
PostPosted: Fri Feb 22, 2008 6:30 am     Reply with quote

There is nothing specific to RS-485 hardware or software that has time-outs that long. But your application software may very well be doing something with long time periods.

Robert Scott
Real-Time Specialties
Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 7:08 am     Reply with quote

What do you mean by "But your application software may very well be doing something with long time periods."?? The master i´m using has a c application running and i had to change the putc and getc functions in both codes as following:

Master:
Code:

   if ( ligar )
   {
      
      EscapeCommFunction( hCom, CLRRTS ); // Clears RTS to receive
      Sleep(4);
   }
   else
   {
      Sleep(2);
      EscapeCommFunction( hCom, SETRTS ); // Sets RTS to transmit

      Sleep(11);
   }


Slave:

Code:

signed int rx_char (char *ch ){

     if (  (*ch = fgetc(COMM))>0 ){
          // Do nothing
        }
   else{
      delay_ms(1);
      output_high(WR);
      delay_ms(1);
      return -1;
   }

  return _NO_ERROR;
}
signed int tx_char (char ch ){

      delay_ms(1);
      output_high(WR);
      delay_ms(1);
      fputc(ch,COMM);
      delay_ms(2);
     output_low(WR);

      return ( _NO_ERROR );

}


In the ccs help it says that we can setup a pin useful for RS-485 interface like "enable=PIN_B3" that set the pin high while transmiting. And i´ve tried that without the delay but i still couldn´t get it working. So i´ve managed the RE/DE problem with delay but for each sended or received character it takes more 4ms because i couldn´t insure that the WR pin was low or high. Is it possible to do that without delays and using only the "enable=PIN_B3" option?? Thanks
Humberto



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

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 7:18 am     Reply with quote

As RLScott said:
"There is nothing specific to RS-485 hardware or software"

Looking at your code, it seems that before the RS485 transceiver there is another device that needs a kind of hardware handshake.
Code:

EscapeCommFunction( hCom, CLRRTS ); // Clears RTS to receive
EscapeCommFunction( hCom, SETRTS ); // Sets RTS to transmit

Could you tell us the meaning of such functions and a brief description of your hardware?

Regarding the control pins of the RS485 transceiver, you just need to define the "enable" pin in the #RS232 directive, tied both control pins RE/DE together -if your application is running in half duplex mode- and let the compiler to do its job.
It is not needed to add any kind of delays.


Humberto


Last edited by Humberto on Fri Feb 22, 2008 7:34 am; edited 1 time in total
Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 7:34 am     Reply with quote

Tha master has a c and c++ code running.
the
Code:

EscapeCommFunction( hCom, CLRRTS ); // Clears RTS to receive


Only sets the pin7 low of the PC comm port that is connected to RE/DE pin of MAX485 through a MAX232

Code:

EscapeCommFunction( hCom, SETRTS ); // Sets RTS to transmit


Does exacly the same thing but is to set the pin high.

The hardware i have since the PC is not equiped with a 485 port i had to pass it through a RS-485/RS-232 converter so i have the pic directly connected to MAX485 that pass through a MAX485 again and then throught a MAX232 and then to the PC. like this

http://www.mikroe.com/en/books/picbasicbook/09/rs485.gif

My problem is that i´ve got a lot of chars to send and receive and i´m already using a slow baud rate and if i increment the time of delay in W/R pin it will increase too much my communications transfers. The only thing that i thing is weard is that after a while it works perfectly...
Humberto



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

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 7:40 am     Reply with quote

Who is controlling the RE/DE pins of the RS485 transceiver close to the PC?
MAX232 T1in is floating!
You need a work around regarding this. There is an easy trick: a hardware solution.
Add a monoestable IC configured in retriggerable mode, trigger it with the Tx line and adjust
the monoestable RC delay using the following criteria:

RC= (minimum bit period + 50% )
being minimum bit period the period for the max expected baud rate

Wire the monoestable Q output to the RE/DE pins and you'll have full hardware control
of the -actually floating- transceiver control pins.

Humberto
Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 9:09 am     Reply with quote

Quote:

Who is controlling the RE/DE pins of the RS485 transceiver close to the PC?

Close to the PC is the PC comm port the pin7 of db9 is te RTS so i think that is enough.
You´re right. Does a pull-down or pull-up resistor do the work? Sorry but i not very familiar with RC filters. Do you know any place where i can get that information or any schematic that could help me? Thanks...
Humberto



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

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 9:41 am     Reply with quote

Quote:

Does a pull-down or pull-up resistor do the work?

Nop. You need to toggle the RE/DE pins to enable /disable Tx and Rx modules inside
the RS485 transceiver.

Following I send you a schematic found in the web.
http://schematics.blogspot.com/2004/11/monostable-multivibrator.html

You will see an application schematic of a dual monoestable IC (namely CD4538).
It has 2 modules inside, you only need to use one of them.

It include a link to get a full manufacturer datasheet, read it and you will see that it is very easy to use. If you are not familiar reading a datasheet, this will help you:
http://www.egr.msu.edu/classes/ece480/goodman/read_datasheet.pdf

Be aware that in the not used module -another half of the IC - ALL the inputs
(T+ T- and R ) must be tied to GND.


Humberto
Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 10:41 am     Reply with quote

Thanks a lot Humberto i´ll read it and try to find out the problem.
esa



Joined: 31 Jan 2008
Posts: 19

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 3:30 pm     Reply with quote

I think, RTS must be connected to T1In and not R1in

Nevertheless, to control your RE/DE line, you can also check here :
http://www.rs485.com/
there is a lot of schematic.
I make this one to control RE/DE line :
1N4148+1 resistor+1cap+1 NAND
http://www.rs485.com/pdffiles/converters/ipc24.pdf
Working very good and very easy to do.
Eric
Humberto



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

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 3:40 pm     Reply with quote

Well, Copperfield in the net !!! Shocked

Lets assume that when the poster (Audi80) show us the reference link, there were
only 2 wires coming from the PC. RTS was not showed at all.
If not I would never ask him to explain us regarding those two "unexplained functions".
Also R1in was without any connection.

it's "a kind of magic" Cool Cool Cool

http://www.geocities.com/sunsetstrip/theater/9609/queen2.html

Humberto
Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

PostPosted: Mon Feb 25, 2008 3:43 am     Reply with quote

Sorry you're right there are errors shown in the link i've posted but they were corrected. One is the connection of the RTS in MAX232, after i repaired those errors it was working i think that the problem might be in the values of my MAX capacitors they should be of 1uF or 100nF but i only had 10uF. Could that be a problem? Confused
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Mon Feb 25, 2008 5:54 am     Reply with quote

As for pull-up, pull-down (620 ohm) and terminating resistor (120 ohm) at http://www.rs485.com/pdffiles/converters/ipc24.pdf ,
can they be switched electronically? For example, if the device becomes the last device on the bus, the terminating resistor shall be connected to the bus etc.

EDIT : the following is clear now
In the right top corner at the given scheme, next to the RS485 connector, there are 4 diodes and 2 other "weird" diodes (dont know their name nor function). I assume that their purpose is protection against high voltages within the bus, am I right? How does this part work, please? I reckon that a high voltage is shorted to ground through one of "unknown" diodes. Could Zener diodes be used instead?

EDIT : Allright, the unknown device is transil which is quite similar to the Zener diode.

Thank you
Regards meereck
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