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

Problem with RS485
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

KISS (Keep it short and simple)!
PostPosted: Mon Aug 22, 2011 7:53 am     Reply with quote

Quote:

In receiving, when RE = DE = 0 and If voltage between A-B is zero ( when A-B both are high) RO should be high but the Proteus model gives RO low. This causes the the program to stay in this routine forever.


Yes, if RO is low your code will loop continuously. That's because in that situation you set i = 0 in the loop and that means the loop will never complete while RO is low.

I'm not at all sure what your are trying to do here. Wait for the line to become idle I assume. That is not a good way to run RS485. Better is to link DE and RE to the same PIC I/O pin and use them as a transmit enable, rather than as here a receive disable. Then when you want to send you enable the transmitter (disabling the receiver at the same time), wait a few microseconds, 10us will generally do unless you've got optoisolators in the 485 line; send your message; disable transmit. Then line is then ready to receive anything sent the other way.

So keep it simple: stay in receive until you need to transmit, and then get back in to receive as soon as possible. There's no need for conditional waits, only simple fixed time delays. You don't need to worry about when the other end is likely to send to you, as you're always ready, unless you are transmitting, in which case you can't receive anyway.

I've just been altering the AN1310 bootloader for RS485, and it works quite well now (not perfect however...)

RF Developer
xeta123



Joined: 20 Aug 2011
Posts: 3

View user's profile Send private message

Re: KISS (Keep it short and simple)!
PostPosted: Tue Aug 23, 2011 7:38 am     Reply with quote

Quote:
So keep it simple: stay in receive until you need to transmit, and then get back in to receive as soon as possible. There's no need for conditional waits, only simple fixed time delays. You don't need to worry about when the other end is likely to send to you, as you're always ready, unless you are transmitting, in which case you can't receive anyway.



This is exactly what the code does. The wait routine is not for receiving but for sending, it is just seeing if the line gets free so that it may start sending data.

The CCS C code is correct, it is just that Proteus MAX487 model RO pin is always low in (idle) receiving / listening mode. Simple Smile
tonyela



Joined: 30 Aug 2012
Posts: 1

View user's profile Send private message

PostPosted: Fri Sep 21, 2012 11:24 pm     Reply with quote

Hello all,
Have anyone get this code up and running?... I am using the 16F877A and still get stuck at wait for bus ready. The attached file is the hardware design. Please check if I connect them correct.
Thank you in advance.
ahh.. I can't attached picture.. but here iit is:
on the 16F877A:
External Clock with 2x22pf connect to OSC1 & OSC2 of 16F877A
RxD from V-terminal connect to RC6/TX of 16F877A
TxD from V-terminal connect to RC7/RX of 16F877A
RO from max487 connect to RB0 of 16F877A
DI from max487 connect to RB3 of 16F877A
/RE and DE from max487 connect to RB4 of 16F877A
on the MAX487:
4K7 ohm connect to PIN B of Max487 and pull down then 56ohm to BUS
4K7 ohm connect to PIN A of Max487 and pull up then 56ohm to BUS
120 ohm terminated on both end.

hope this make sense.

Thank you again
[/img]
ygt



Joined: 06 Jan 2014
Posts: 2

View user's profile Send private message MSN Messenger

rs485 communication master to more slave
PostPosted: Sat Jan 11, 2014 8:43 am     Reply with quote

ex:1 master and 3 slave
i want to data receive and send between.i using rs485.pls.help me.i need simple project or master-slave code about rs 485. i tired.please help... javascript:emoticon(':cry:')
Ttelmah



Joined: 11 Mar 2010
Posts: 19613

View user's profile Send private message

Re: Corrupt MAX487 Proteus Model
PostPosted: Sat Jan 11, 2014 10:22 am     Reply with quote

xeta123 wrote:
Okz guys the culprit was the proteus max 487 model itself.

The model fails to fulfill the datasheet condition:

http://www.embeddedj.co.th/downloads/sheets/ic/MAX485.pdf See page 10 under heading: Function Table

In receiving, when RE = DE = 0 and If voltage between A-B is zero ( when A-B both are high) RO should be high but the proteus model gives RO low. This causes the the program to stay in this routine forever

Code:

void rs485_wait_for_bus(int1 clrwdt)
{
   int16 i;

   RCV_OFF();
   for(i=0; i <= (rs485_wait_time*20); ++i)
   {
      if(!input(RS485_RX_PIN)) // always true because of bug in proteus model
         i = 0;
      else
         delay_us(50);

      if(clrwdt)
         restart_wdt();
   }
}


I have worked around with this in simulating in full duplex mode using two max487 at each side.


Actually the model is correct.

The MAX487, _does not define what it's output should be when the lines are equal_.
This is why biasing the A and B rails is so important. Some drivers do make this guarantee (Texas do a range), but the output for A less than 200mV from B (in either direction), is 'indeterminate'. It'll normally stay at the last level.

Look at the definition for RO in the data sheet.

It is '1' if the inputs are left open (floating), but not if both are driven to the same voltage.

Proteus are giving you a strong warning here about what can happen if the rails are in such a state.

Though I don't like Proteus I've seen too many real situations where this happens.

Best Wishes
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 Previous  1, 2
Page 2 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