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

Bi-directional rs232 link.

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



Joined: 20 Dec 2009
Posts: 23

View user's profile Send private message

Bi-directional rs232 link.
PostPosted: Sat Mar 20, 2010 9:30 am     Reply with quote

Hi everybody,

I need advice on setting up a bi-directional rs232 link.

I'm using a 18f2321 with v 4.104 compiler software. I'm using the UART hardware so the MULTI-MASTER mode is not available. I'm using National 96176 rs485 chips.

My current program seems to be reading part of the transmitted data back. The INT_RDA interrupt fires when I transmit data, even with the receivers ability to transmit commented out. The rs485 IC's were just changed.

From the #USE rs232 page of the manual:

========================================

SYNC_SLAVE Makes the RS232 line a synchronous slave,
making the receive pin a clock in, and the data
pin the data in/out.

SYNC_MASTER Makes the RS232 line a synchronous master,
making the receive pin a clock out, and the
data pin the data in/out.

SYNC_MATER_CONT Makes the RS232 line a synchronous master
mode in continuous receive mode. The
receive pin is set as a clock out,

========================================
Do I make one end a SYNC _MASTER and the other a SYNC_SLAVE?

- OR -

Can I make both ends at SYNC_SLAVE until an interrupt happens, switch to SYNC_MASTER mode to transmit, and then return to SYNC_SLAVE mode to wait for the next interrupt?

Since the hardware at both ends of the link will be exactly the same it would be nice if I could used the same software. There will never be more that 2 units on the link so I'm hoping I can avoid the more complex techniques of the sample programs.


Thanks, Al
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Sun Mar 21, 2010 3:16 am     Reply with quote

Your thread is entitled 'RS232', yet you are using RS485....
Not a good start.

Now, you need to understand, that RS232, and RS485, are electrical signalling standards. Over both these standards (or TTL), you can send either asynchronous data, or synchronous data. Which are you wanting to send?.
I'd guess, that you want to send async data. 99+% of RS485 busses use this. In which case you do _not_ want to select the sync bits. To handle 'sync', you would need to be sending a permanent 'clock' connnection from the master, the data bus itself (another wire, with reversible data direction), and a third data direction control wire. Unless this is what you really want to do, the sync selections are not used.

What you should be looking at, is the 'ENABLE=pin' option in the use RS232 statement. On the DS96176, connect the /RE, and DE pins together, and connect both of these, to the pin you select as the 'enable' pin on the PIC. Then the transceiver is automatically switched to 'transmit', when data is being sent, and to receive the rest of the time.
Then you _must_ bias the bus so that when nothing is sending, it idles to an 'off' state. A search here will find a lot about this. Basically though you need to ensure that the voltage A-B, on the bus is slightly greater than 0.2v, when nothing is driving the bus. You may need to terminate the bus as well, but this is only 'required', if the bus is long, or data rates are high, and also to help reduce noise on the lines.
Finally, add a pull up resistor on the line from the RO pin to the PIC's RX pin. 10KR or similar.

Best Wishes
Allan



Joined: 20 Dec 2009
Posts: 23

View user's profile Send private message

PostPosted: Sun Mar 21, 2010 12:22 pm     Reply with quote

Ttelmah wrote:
Your thread is entitled 'RS232', yet you are using RS485....
Not a good start.


Not really. From the Wikipedia article on RS485 (Formally called EIA-485)

"EIA-485 only specifies electrical characteristics of the driver and the receiver. It does not specify or recommend any data protocol. "

I loaded an early working version of the program into both boards. The boards are already wired as you suggested (enable pin is used, RO and /DE shorted together) Here's how the port is configured

Code:


#use rs232(uart1, baud = 19200, Enable = EPIN, stream = Remote, DISABLE_INTS)



This simple program only sends a 'U' or 'D' to increment/decrement the display value on the receiving unit. I had the debugger send the character received by the in the #INT_RDA ISR to the monitor and _Every Time_ I got a U or a D - No signs of noise.


Finally, I put a storage scope in the data lines. DO sits at 2.5V, /DO sits at 2.2 V, and both pins have a crisp 2.5V rectangular waves when active. My scope also shows no noise after transmitting.

So I've got good hardware - the software is what's killing me.

Any advice? If you (or anybody else) were writing software from scratch how would you set up a very simple 2 unit bi-directional comm line? I'm trying to avoid the complicated addressing schemes used in the sample programs. I only need to send an int16 between 2 units.

Thanks for your help Ttelmah,

Allan
jbmiller



Joined: 07 Oct 2006
Posts: 73
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 21, 2010 1:01 pm     Reply with quote

The 'simplest' solution , since there are only ever two units on the com bus, is to have a 'master' and a 'slave'. CCS has demo code in the examples files...makes a good starting point.
If you want both units to be either master or slave, that opens a whole can of worms...requiring timeouts, bus mastering, collision advoidance, error checking, etc.

For over 25 years I've run remote SCADA systems using the 'simple' solution, on a true single wire bus for over 20 miles to the remotes. Noise has never been an issue, no bus arbitration problems,etc.
Allan



Joined: 20 Dec 2009
Posts: 23

View user's profile Send private message

PostPosted: Sun Mar 21, 2010 1:03 pm     Reply with quote

I need to clarify something in my post.


http://www.ccsinfo.com/forum/viewtopic.php?t=42046


Ttelmah already gave me the program I asked for (Thanks!) The real problem must be in my modifications to his program.

Knowing the hardware is good I can now sweat over the software.

Thanks again.

Al
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Sun Mar 21, 2010 1:43 pm     Reply with quote

Allan wrote:
Ttelmah wrote:
Your thread is entitled 'RS232', yet you are using RS485....
Not a good start.


Not really. From the Wikipedia article on RS485 (Formally called EIA-485)

"EIA-485 only specifies electrical characteristics of the driver and the receiver. It does not specify or recommend any data protocol. "

Exactly.
You are sending async serial over RS485. No RS232 involved anywhere, so why say 'RS232 link'....
Just because CCS are stupid and refer to the TTL async port on the PIC as 'RS232', you don't have to join them in this idiocy... Smile

Now, you say you have the enable, have you got the pullup resistor on the RO pin. Otherwise you _will_ potentially receive garbage when transmitting. Also have you got the bus bias, or you will again potentially see garbage, when nobody is transmitting.

Best Wishes
Allan



Joined: 20 Dec 2009
Posts: 23

View user's profile Send private message

PostPosted: Sun Mar 21, 2010 3:31 pm     Reply with quote

Ttelmah wrote:


You are sending async serial over RS485. No RS232 involved anywhere, so why say 'RS232 link'....
Just because CCS are stupid and refer to the TTL async port on the PIC as 'RS232', you don't have to join them in this idiocy... Smile



Thanks for clarifying that. I've got to do some studying and get the terminology straight.

Al
jbmiller



Joined: 07 Oct 2006
Posts: 73
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 21, 2010 3:54 pm     Reply with quote

gee Ttelmah, please give CCS a break. They're just using the convention of saying 'RS232' as the common standard for serial communications. Sure it's 'wrong' but everyone understands it. Like saying 'I need a xerox, when really it's a photocopy, or give me a kleenex when really it's a [spam] tissue.
I've been in this trade since teletypes were the 'man machine interface', egads even teletype was the NAME of the company that made the ASR-33 machines. Back then it was 20mA current loops,60 if you had some real distance to go! There weren't any UARTs yet either,had to roll your own with 7400 series chips. Man, that was the early 70's....shoot 40 years ago......the good old dayze !

Jay
Allan



Joined: 20 Dec 2009
Posts: 23

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 8:52 pm     Reply with quote

Ttelmah wrote:


Finally, add a pull up resistor on the line from the RO pin to the PIC's RX pin. 10KR or similar.

Best Wishes


This turned out to be the problem. !2 hours down the drain because the engineer who designed the board left this part out!

Thanks again for your help, Ttelmah.

Allan
bkamen



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

View user's profile Send private message

PostPosted: Tue Mar 23, 2010 10:50 pm     Reply with quote

jbmiller wrote:
gee Ttelmah, please give CCS a break. They're just using the convention of saying 'RS232' as the common standard for serial communications. Sure it's 'wrong' but everyone understands it. Like saying 'I need a xerox, when really it's a photocopy, or give me a kleenex when really it's a [spam] tissue.
I've been in this trade since teletypes were the 'man machine interface', egads even teletype was the NAME of the company that made the ASR-33 machines. Back then it was 20mA current loops,60 if you had some real distance to go! There weren't any UARTs yet either,had to roll your own with 7400 series chips. Man, that was the early 70's....shoot 40 years ago......the good old dayze !


One important item about this is that WE don't know if the USER posting the problem knows and so it CAN lead to confusion.

I've had plenty of bosses who came to me saying, "this is what I want" using the wrong terms to describe their needs.

As I tried to picture some of these things with all the wrong terminology, it turns out what I pictured was completely inline with what they were saying but NOT what they were meaning!!

DOH!

So being a technical environment, until everyone is agreed on the misappropriation of terminology, the correct terminology should be used.

You know what I mean.

And yea, my first modem was 300baud direct connect with a 3pos switch.
ANS-OFF-ORG

My friend was really lucky. His was acoustic coupled. (wink) We had to build boxed for our Atari 800's to control the modem on and off the line to answer the phone to run our BBS's.

-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