How to check whether transmition (Tx) is finished in CCS? (RS485 related question)

Thread Starter

jkcobain

Joined Jun 8, 2014
40
Hello, everyone!

I'm just learning the RS485 standard, so I still have some doubts about it. My main question so far is: when using a PIC(16f887), how can I make sure that the las byte was sent, in order to change the bit of the MAX485 to receive mode?

Also, I'm communicating 3 devices, but two of them (one is the PC) use RS232 as default, so I will have to use converters in order to be able to get the 3 of them connected. And my question is almost the same for these. How is the Transmit/Receive mode controled in these devices? (these devices http://lghttp.14131.nexcesscdn.net/806B12/gridconnect/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/G/C/GC-ATC-106_1.jpg I don't buy them yet, but I think is my best option for the convertion)

Thank you in advance!
 

Picbuster

Joined Dec 2, 2013
990
Hello, everyone!

I'm just learning the RS485 standard, so I still have some doubts about it. My main question so far is: when using a PIC(16f887), how can I make sure that the las byte was sent, in order to change the bit of the MAX485 to receive mode?

Also, I'm communicating 3 devices, but two of them (one is the PC) use RS232 as default, so I will have to use converters in order to be able to get the 3 of them connected. And my question is almost the same for these. How is the Transmit/Receive mode controled in these devices? (these devices http://lghttp.14131.nexcesscdn.net/806B12/gridconnect/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/G/C/GC-ATC-106_1.jpg I don't buy them yet, but I think is my best option for the convertion)

Thank you in advance!
RS485 are you using: a:two wire b:4 wire mutidrop simplex? sync( clock pll at edge data) or a sync?

using a normal 1/2 duplex protocol ( mostly used on a two wire rs485 connection)
All units are in receive mode. ( receive lines are monitored).
When no action one station can claim the line by starting the transmit

soh [address] [stx] [ data] [eot] [two byte checksum]
sending you have one buffer[n] send n chars when done wait, depending on transmission speed 5 chars tx time.

receiver check for address when correct it will read to EOT + 2 checksum chars.
if checksum false then reply soh [address] [nack] [eot] checksum.
when all ok go in receive mode.
Never send data when you receive bytes.

Yes collision will occur in crabbing the line ( give low priority to a station by increasing waiting time)
 

Thread Starter

jkcobain

Joined Jun 8, 2014
40
RS485 are you using: a:two wire b:4 wire mutidrop simplex? sync( clock pll at edge data) or a sync?
I want to use half-duplex, async.

And I already know that theory you're talking about. What I don't know is HOW TO change the mode to transmit/receive... Well, I don't know how the converters work. But I know how MAX485 works, and it needs a bit to set the mode either to transmit or receive; so I would like to know whether I have to worry about that bit when using one of the converters like the one in the image in the link I posted before.
 

Thread Starter

jkcobain

Joined Jun 8, 2014
40
Poll the TRMT bit of TXSTA register. This bit goes high when the last bit has been sent.
Hi! I've been looking for info about this, but it still seems uncertain to me. Do I have to use the RS485 library? Cause I've never used that library. I was thinking on writing my program just like if it where for RS232, and only adding that additional bit...
 

Sensacell

Joined Jun 19, 2012
2,564
Thank you. That gives me an idea on how to do it.
Note that this method may not work as you expect, using this bit will result in stop bits getting chopped off.
Loop what you send out to your RX, use the receiver interrupt flag to tell you when a complete character has been sent.
 

Papabravo

Joined Feb 24, 2006
12,898
Hi! I've been looking for info about this, but it still seems uncertain to me. Do I have to use the RS485 library? Cause I've never used that library. I was thinking on writing my program just like if it where for RS232, and only adding that additional bit...
My old man used to say you don't have to do anything except die. A raw processor is the ultimate testament to individual liberty -- you can literally do anything you want.
 

Thread Starter

jkcobain

Joined Jun 8, 2014
40
Note that this method may not work as you expect, using this bit will result in stop bits getting chopped off.
Loop what you send out to your RX, use the receiver interrupt flag to tell you when a complete character has been sent.
This sounds really weird to me. Won't I get errors in the communication by doing this? I never heard such a method...

My teacher told me once I should never connect voltage to a PIC output, because it could get damaged, and Tx would receive data when other peripherals want to transmit... Though truth is I have never verified what she told me
 

Thread Starter

jkcobain

Joined Jun 8, 2014
40
My old man used to say you don't have to do anything except die. A raw processor is the ultimate testament to individual liberty -- you can literally do anything you want.
Yes! that is for sure! The problem is that I actually don't know whether the RS485.c should be used in order for me to be able to use that bit. I mean, my question was literal :/
 

Sensacell

Joined Jun 19, 2012
2,564
RS-485 is a half-duplex interface- you never transmit and receive at the same time.
When you are in transmit mode, you just discard all the characters that are received.

Most RS-485 interface chips have a TX enable input, this is how you switch between TX and RX modes. Leave the RX enabled and it will "hear" whatever data is on the line, both external and your own transmissions. The chips have separate TX input and RX outputs, no voltage contention issues.

RS-485 is not common and requires some specific hardware to manage TX and RX, libraries wont work unless they are written for the hardware you have.

"converters" between RS-485 and RS-232 are really sketchy, don't expect plug and play operation unless you know exactly how the devices use the communication link.
 
Last edited:

Picbuster

Joined Dec 2, 2013
990
I want to use half-duplex, async.

And I already know that theory you're talking about. What I don't know is HOW TO change the mode to transmit/receive... Well, I don't know how the converters work. But I know how MAX485 works, and it needs a bit to set the mode either to transmit or receive; so I would like to know whether I have to worry about that bit when using one of the converters like the one in the image in the link I posted before.
Ok I understand your question now.
The converter mentioned will force the full duplex, using handshake signals, 1/2 duplex.
However you could face a timing problem at the 485 site look at the turn around time from the converter and add 15%. test it with a scope if no data sheet is available. I used those converters @ 115Kb no problems rather than the turn around I set is to 30mS.
 

Papabravo

Joined Feb 24, 2006
12,898
You can always use the libraries if you understand what is in them. If they don't meet your needs then you have to replace them with one of your own. The good news is that in most cases you can use the libraries as a starting point for rolling your own solution.
 
Top