RS232 to RS485


Closed Thread
Results 1 to 23 of 23

Thread: RS232 to RS485

Hybrid View

  1. #1
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    I think ive finally got a good way of doing it. Im going to use the 555 method in the main controller. The main controller is the bit that connects all the devices to the PC. At the moment its RS232 but i plan to make a USB or ethernet version. All the devices need to be addressed seperately but there isnt really a method to set the address on the device itself so it would mean plugging each one in seperately and assigning an address. Im going to add another wire between each device that is either high or low. The master will make the wire high which will tell the first device on the line to reply. The master will assign it an address then the device will make the wire high for the next device and so on.

    That might seem a little complicated but it should do exactly what i want and it also has the advantage of allowing 2 devices to be swapped around. The 2 that are swapped will pick up each others addresses and continue asif they were still in their origional positions. It does ofcourse mean that they wont be hot pluggable but thats fine.

  2. #2
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Assume a one-byte address. Assign each device an initial address of 0xFE. Connect one at a time and have the master send a message to 0xFE to reset its address to 0x01, 0x02,...,0xNN, etc.

  3. #3
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    The origional idea was similar to that. I normally start all messages with [255] then a command. EG, 254 would mean set address. Any device connected would take the 3rd byte and set it as its address.

    The way im doing it now is a little more complicated. Each device will know how far away from the master it is. Its complicated a little further because there are 2 sockets on each device for in and out but it doesnt matter which way you connect them.

    There are 5 wires (and a screen):-
    1) Power +
    2) Power -
    3) Data A
    4) Data B
    5) Not thought of a name for this yet

    The master will keep #5 high constantly. The first device connected to it will check both of the sockets to see if #5 is high on it. If it is then it knows that socket is the input. The default is for both sockets to be inputs so #5 will be low by default unless the master is present. This means that only the first device will see a high on #5 so only that device will set itself an address.

    Since the last post ive changed the way the addressing works so there is no need for a PIC chip in the master. All devices will default to [0]. The first one to get a high on #5 will add 1 to the address and save it (it is now device 1). It will then switch to send mode and send the address out to all the other devices then switch back to receive mode. All the other devices will use the new address as the default.

    The first device will now make #5 high on whichever socket is still low which causes the next device to set itself an address etc.

    I know it sounds complicated but it means that all the devices will automatically address themselves. If i connect all the devices in a straight line then it doesnt matter which order i put them in along the line, they will still function in the correct order.

    Once all the devices have a unique number that they can be accessed by then i can set a second address through serial. The data would only require the second byte changing and they can be accessed by their specific address or by their position in the line. It saves having to connect one up at a time to address them or having a button on the back that you press to accept the address.

    The position address will be reset everytime the devices turn on but the address that is set by sending a command will be saved in the EEPROM and only change when it gets a change command.

    Im using the 555 method in the master but not in the individual devices. Each device only needs to send a small amount of data when they first turn on and possibly when a certain command is sent. They should never need to send data during normal operation

  4. #4
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Hi, Ive been testing this RS485 stuff out tonite. I had bypassed it before to get everything else working. Now ive tried to get the RS485 bit working and ive found a little problem. The first 1 or 2 bytes seem to get missing from the data. I think its because the 555 doesnt react quick enough to the data. Im using 115200 baud. Is there anything i can do about this problem?

  5. #5
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Attached Images Attached Images  

  6. #6
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    So what your saying is scrap the 555 idea and go back to using RTS. I guess that is an option. Ill have to look into how that will affect the software. I know i can easily control RTS in VB using the comm control but i do like to use API for speed. Ive not had the need to use handshaking before so i should probs read up on that.

    Thanx for the suggestion and the diagram. Now i see the point in the MAX232 having 2 ins and outs

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,139


    Did you find this post helpful? Yes | No

    Default

    Why not sending some control characters then wait for the start character, dump it and get the next.

    Like this:

    Send "#######$data"

    on PIC side:

    Hserin [wait("$"),str mydata\data_bytes]

    Ioannis

  8. #8
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    The first 1 or 2 bytes seem to get missing from the data. I think its because the 555 doesnt react quick enough to the data. Im using 115200 baud. Is there anything i can do about this problem?
    I doubt very much whether it's the 555. That method is widely and successfully used for automatic control of line direction. The fact that subsequent bytes are OK would also seem to indicate it's not the 555. Are you using termination resistors? They are absolutely necessary at 115200.

  9. #9
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    I am using a termination resistor at the end with the 555 aswell as 2 biasing resistors exactly as shown in the diagram in your first post. I have the RS232 to RS485 converter plus 2 lights on breadboards at the moment. The MAX485 chips are less than 5cm apart but i can add another terminating resistor at the end just to be sure.

    Ive been thinking about this one and i think i got it the wrong way round. The thing that got me thinking is that the offset is constant even if i stop sending data then start again. You would expect it to keep shifting one or 2 bytes further out everytime the 555 gets chance to turn back off. I looked at how the circuits reacted to the data and it seems they are actually getting an extra byte or 2. I think that may be to do with the way ive programmed it but now im looking in the right place i have a better chance of solving the problem.

    I do like the idea of using a 555 because it allows me to have a status light that doesnt flash too quick to see and doesnt need any other components

  10. #10
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    It turns out it was a programming problem. As the chips start up the first one sends out a byte to tell the others how many chanels it has then goes into receive mode. The second one then does the same thing but the byte it sends out gets counted as data by the first light. Im really not sure why it was sometimes 2 extra bytes but ive reprogrammed it and it seems to be working perfect now. Sorry for wasting your time

Similar Threads

  1. UART vs software RS232
    By Michael in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 5th September 2008, 18:27
  2. RS232 into 2 PC ports
    By manxman in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th August 2008, 13:33
  3. PIC18F4680 to PC via MAX232 (RS232 serial) no output
    By opticsteam1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th April 2008, 20:39
  4. Using 16f676 with comms
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 28th October 2005, 20:01
  5. rs485 to rs232 smart switch
    By RSSHARPE in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th June 2004, 08:44

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