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

Discussion in 'Embedded Systems and Microcontrollers' started by jkcobain, Mar 31, 2016.

  1. jkcobain

    Thread Starter Member

    Jun 8, 2014
    31
    5
    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/...33525d08d6e5fb8d27136e95/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!
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,357
    Poll the TRMT bit of TXSTA register. This bit goes high when the last bit has been sent.
     
    jkcobain likes this.
  3. Picbuster

    Member

    Dec 2, 2013
    373
    50
    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)
     
  4. jkcobain

    Thread Starter Member

    Jun 8, 2014
    31
    5
    Thank you. That gives me an idea on how to do it.
     
  5. jkcobain

    Thread Starter Member

    Jun 8, 2014
    31
    5
    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.
     
  6. jkcobain

    Thread Starter Member

    Jun 8, 2014
    31
    5
    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...
     
  7. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,128
    266
    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.
     
  8. Papabravo

    Expert

    Feb 24, 2006
    10,136
    1,786
    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.
     
  9. jkcobain

    Thread Starter Member

    Jun 8, 2014
    31
    5
    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
     
  10. jkcobain

    Thread Starter Member

    Jun 8, 2014
    31
    5
    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 :/
     
  11. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,128
    266
    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: Apr 1, 2016
    jkcobain likes this.
  12. Picbuster

    Member

    Dec 2, 2013
    373
    50
    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.
     
    jkcobain likes this.
  13. Papabravo

    Expert

    Feb 24, 2006
    10,136
    1,786
    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.
     
    jkcobain likes this.
  14. jkcobain

    Thread Starter Member

    Jun 8, 2014
    31
    5
    Thank you guys! Things are clearer for me now, though not easier!

    You were really helpful!
     
Loading...