This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to create and use a frame with RS485 ?

Dear my all friends,

I am a new user of RS485 serial communication but I do not know how to trans and receive multiple bytes without any data loss as well as errors or jitter.

My MCUs are 89C51 family (89S51,DS89C420..), in fact, my trouble is how to control a communication session with multiple-byte data frame using serial port of 89C51 family. I should use interrupt routines or main loop to process that session ???

Any one help me, please..., thanks!

  • I can not tell all about 485 multinode in a brief post, but here is the skinny.

    1) NOBODY but the master talks without permission
    2) in a circular fashion the master ask the slaves "do you have data" and the slaves either transmit the data or answer "no"
    3) to address the slaves, use the 9 bit UART mode
    4) The UART interrupt happen 1/2 to 1 bit time before transmission is complete (at the start of or in the middle of tha stop bit) so always wait (I use 2, one is supposed to be enough) bit time before "turning the bus"
    5) before anything else, read 10 ways wo bulletproof 485 found here
    http://www.national.com/apnotes/Analog-Interface.html.

    Go through this, and if you then have specific questions, post again.

    Erik

  • Let me express my heartfelt thanks to Mr. MALUND for his helpful advice.

    I will practise myseft then ask you again sir, ... It's hard for me to do communication between RS485 nodes because I have only the two put(byte) & get(byte) tools, could you show me the way to build another effective tools those could send a series of numbers or string, but still use the least code 'cause my memory is limited.

  • [joke]
    Q: How can you eat a whole whale?

    A: One bite at a time!
    [/joke]

    "I have only the two put(byte) & get(byte) tools"

    That's all you need - you can only put 1 byte at a time to the UART, and get 1 byte at a time from the UART.

    To put or get multiple bytes, you just call put() or get() the appropriate number of times!

    Remember: after you put a byte to the UART, it takes a finite time to transmit - so you must wait for it to finish before you put the next byte!
    Similarly for receiving.

    (There is an example of interrupt-driven serial IO in the Downloads section).

  • "I have only the two put(byte) & get(byte) tools"

    show the code for those.

    If you use "Keil supplied" give it up, they are 232 based and do not have direction control

    Erik

  • you will need StartTransmit() and TransmitDone() to control flow in addition to the above.

  • The problem here is that I could not discriminate one data byte (index) among multiple-data bytes and other header bytes. What will I have to do when a slave interrupt me to send its-one-byte (of course, after it is requested), how can I know what I have received ?

  • Thanks for yours discussion,...