How to determine 485 network is not busy in half-duplex


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: How to determine 485 network is not busy in half-duplex

    Thanks Henrik, Dave and Darrel!
    I was forlorn late last night - felt a bit better so I thought I would tackle my own idea, only to find out I do NOT have write privileges to the RCREGx register, and as it now seems, that would not be the way to go.
    Darrel, I will read this over and see what I can do with it, I completely missed the RCIDL bit as it was buried in the Baud Rate Generator section, but, sure 'nuff on page 349 of 622 (who REALLY calls these things datasheets any more? I can remember the old 7400 data sheet........) it does say:
    'To assure that no actual data is lost, check the RCIDL bit to verify that a receive operation is not in process.' Dang that Darrel, his frontal lobes must be HUGE! Thanks for that Darrel, I'll try some stuff tonight.

    I am hoping that it can be done effectively using 2 wire, but as its just for me, I can change to 4 wire or use an 'attention' line if need be, just not as cool.

    So, according to the app note, this looks a lot like the forunner to CAN? I have worked with CAN and found it too troublesome - even for work solutions which is why I wanted to use 485 and figure out my own or use someone else's with any changes.

    One thing I had not thought about before reading the app note (Thanks again), it looks like I can set priorities, something I had not thought of - thought the nodes would arbitrate that....... The note's logic is pretty much what I started with, without MIDs and the nifty way of determining message priority delays. The part about determining bus idle is also interesting. This J1708 protocol might just be the ticket.

    Its interesting that the data into the 485 chip goes into the DATA ENABLE while the DATA INPUT is held at ground and the result is apparently NO electrical bus contention.
    I have my 75LBC184 wired in the conventional sense with RE/DE tied together and driven by the proc as a 485 ENABLE and the TX and RX going to their re3spective inputs/outputs.

    So, if I use the 'standard' 485 wiring, I should be able to follow the note as:
    The steps to arbitration are as follows:
    1. Wait for the bus to become Idle.
    2. Wait the required priority delay after the Idle period has started.
    3. Make sure the bus is still Idle. If the bus is not Idle, go back to step 1.
    4. Transmit the device MID (or my address of the node) on the bus.
    5. Receive the transmitted MID and determine that the sent MID matches the received MID.
    6. If the match was successful, we have claimed the bus. Send the packet.
    7. If the match failed, we lost the arbitration. Continue to step 8.
    8. If this was the first collision for this packet, go to step 1.
    9. Wait for the bus to become Idle.
    10. Wait for a pseudo-random number of bit times (between 0-7).
    11. Go to step 3.

    Has anyone else use this? I'll start coding a trial tonight!
    Thanks Guys, this will help!
    -Steve
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    970

    Default Re: How to determine 485 network is not busy in half-duplex

    I have done multi-master RS485 many years back. I found the AN01230 interesting in how they achieve the multimaster operation.

    What I did involved a little an extra 485 chip, but, essentially utilised the same principles.

    I had a main RS485 transmitter and a separate RS485 listener chip on the same board. Whatever goes out the transmit line is visible back again on the input line via the listener chip. So, any data corruption due to a collision can be detected and the transmit process can be re-started. The rest of the arbitration process is essentially the same except I use discrete IDs for each RS485 station like in any such multi-device setup and the system worked very well.

    You can stop transmitting the moment you see a single byte error in your packet - when sent character is not same as received character.

  3. #3
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Default Re: How to determine 485 network is not busy in half-duplex

    Thanks Jerson. I made the mistake of already having the board made so I would like to try to see if I can do it with just one 485 transceiver. The J1708 looks like it is still being used and if I cannot get a modified J1708 protocol to work with a 485 connected the normal way, then my next try would be to try an actual J1708 transceiver. Maxxim makes one and it look as if it would be a drop-in replacement so I would have the expense of re-doing the board design.
    I think I have base code working but for some reason the 485 enable line sits high - even after the packet should have been delivered..... which tells me the program thinks there is still stuff to transmit...... looking into it now....
    Regards,
    Steve

    Code below:
    Code:
    Node_ErrChk:'-------------------------------------------------------------------
    'Checks the received node packet for data integrity and sends an ACK if good or a NAK if bad
                      NodeWord=Node_Addr+Node_Cmd_Resp+Node_Bd+Node_Port_Dev
                      Node_Sum_temp=NodeWord.byte0 ^ $FF                            'Creates a local temp sumcheck used for comparison
                      if Node_Sum_Temp <> Node_Sum then                             'If the received checksum and the local checksum don't match, then.... 
                         error=1                                                    'Turns ON error LED
                         Node_Cmd_Resp=$03                                          'Form our NAK response
                         Node_Addr=Address                                          'What our local address is
                         Node_Bd=0                                                  'Doesn't matter, we are asking for a retransmit
                         Node_Port_Dev=0                                            'Same as above
                         NodeWord=Node_Addr+Node_Cmd_Resp+Node_Bd+Node_Port_Dev     'Create our checksum
                         Node_Sum=NodeWord.BYTE0 ^ $FF                              'ditto
                         ncts=1                                                     'Enable transmission of 485 interface
    NodeLineBusy2:       if BAUDCON1.6=1 then pauseus (Address*10)                  'Checks to see if the receive operation is idle(1), if it is, pause for address*10 uS for random
                         if BAUDCON1.6=0 then NodeLineBusy2                         'Receive operation is still busy, if not, send packet
                         hserout [sync,Node_Addr,Node_Cmd_Resp,Node_Bd,Node_Port_Dev,Node_Sum]   'Send command
                         while not TXSTA1.1 : wend                                  'Wait for USART to finish xmitting
                         ncts=0                                                     'Places 485 interface back into receive mode
                      else                                                          'OR....... 
                         Status1=1                                                  'Turns ON LED
                         NodePktResp=Node_Cmd_Resp & $0F                            'Strips off high order nibble to check for a NAK, put in local temp var - keeps packet integrity
                         if NodePktResp=$03 then goto Node_ReXmit                   'Got a NAK from the Control Computer so send it again
                         if NodePktResp=$02 then Node_ErrChk_Exit                   'We were ACKd, so just leave it alone
    'Now we have received a node packet, believed to be good, so we will ADD $02 to 
    'the Node_Cmd_Resp byte we received and transmit back to Control PC so the PC 
    'knows everything is OK in our world....... and figure a new Checksum......
                         Node_Cmd_Resp=Node_Cmd_Resp + $02                          'Adds the ACK to the byte for our response
                         NodeWord=Node_Addr+Node_Cmd_Resp+Node_Bd+Node_Port_Dev     'Build our new checksum
                         Node_Sum=NodeWord.BYTE0 ^ $FF                              'ditto
                         ncts=1                                                     'Enable transmission of 485 interface
    NodeLineBusy3:       if BAUDCON1.6=1 then pauseus (Address*10)                  'Checks to see if the receive operation is idle(1), if it is, pause for address*10 uS for random
                         if BAUDCON1.6=0 then NodeLineBusy3                         'Receive operation is still busy, if not, send packet
                         hserout [sync,Node_Addr,Node_Cmd_Resp,Node_Bd,Node_Port_Dev,Node_Sum]   'Send command
                         while not TXSTA1.1 : wend                                  'Wait for USART to finish xmitting
                         ncts=0                                                     'Places 485 interface back into receive mode
                      endif
    Node_ErrChk_Exit:
                      Status1=0                                                     'Turns OFF LED
                      Error=0                                                       'Turns OFF LED if it was ON
                      node_PacketRcvd=0                                             'Zero the switch so we don't send other bytes
                      return
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

Similar Threads

  1. give an address to pic on rs-485 network
    By russellperry in forum Ethernet
    Replies: 2
    Last Post: - 8th February 2014, 23:50
  2. USB CDC serial duplex string example wanted
    By russellperry in forum USB
    Replies: 0
    Last Post: - 31st January 2014, 19:33
  3. PICs in a RS-485 network?
    By atomski in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 12th November 2011, 10:52
  4. RS 485 network
    By mychangl in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 25th November 2008, 10:35
  5. Slave Databuffer - RS-485 network
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st June 2005, 19:36

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts