This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Sample code for RS485 through UART integratted with TM4c129x

Hi All,

i'm integratting RS485 into TM4c129x. This is UART communication. I'm using Code composer studio version 6.
Can you provide sample code for this.

Regards & Thanks

Aravinth

  • //
    // Initialize the UART. Set the baud rate, number of data bits, turn off
    // parity, number of stop bits, and stick mode.
    //
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 38400,
    (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
    UART_CONFIG_PAR_NONE));
    //
    // Enable the UART.
    //
    UARTEnable(UART0_BASE);
    //
    // Check for characters. Spin here until a character is placed
    // into the receive FIFO.
    //
    while(!UARTCharsAvail(UART0_BASE))
    {}
    //
    // Get the character(s) in the receive FIFO.
    //
    while(UARTCharGetNonBlocking(UART0_BASE))
    {}
    //
    // Put a character in the output buffer.
    //
    UARTCharPut(UART0_BASE, ’c’));

    This example is taken from the Tivaware manual. There is plenty of further useful knowledge on the remaining 706 pages.

    With such a generic question, I believe a generic question will suffice... But if you have a more specific issue, please clarify and I am sure that the fellow engineers here will be able to assist further.

  • Hello Aravinth

    When you mention RS485, what exactly are the signals on the RS485 bus are you using?
  • Hi Amit,
    RS485 slave i'm using. And my stack is SILA. Do you have any example for this.

    Regards,
    Aravinth
  • Hello Aravinth.

    No we do not have example for SILA. And my original question still remains, what signals are being used on the RS485 bus (just transmit receive or flow control as well).

    Another question is that how are you interfacing the TM4C to the RS485 bus. I hope you have a connector board in between?

    Once we can resolve these questions, we will progress on the software discussion
  • Thanks for your response Amith.
    1. It is only for transmit and receive data
    2. We have a connector

    Regards,
    Aravinth
  • Aravinthkumar jayaprakasam said:
    1. It is only for transmit and receive data

    How is the direction of the RS-485 transceiver controlled?

    E.g. is there a separate signal for direction control, or does the RS-485 transceiver contain an automatic direction control?

  • Dear Aravinth,

    I'll try to be useful and drop a reply that can be of service to yourself and to others.

    The first thing to do on a forum is to read its guidelines - and they are usually the same everywhere.

    Unfortunately, your post reaches the border of unpolite: you go right into asking for code without even explaining what you have tried to do so far. You are likely to receive nothing useful back... For example, I did exactly what you asked for: posted code to communicate via serial port - and I was sure it would be of no good use.

    So a general aid to fellow developers who land here: embedded electronics ain't rock science (actually, we are happy it is!), but it does require some effort and dedication. Vendors do as much as possible to supply learning and development resources, but users will need to have get theirs hands dirty and go through them. An E2E forum like this is a resource to come only after you've already tried something apparently according to those documents, but it haven't yet worked - or for discussions on best practices, improvements, eventually for non-documented glitches.

    Having said that, you will research further about RS485 and see that such "nice name" is specific only to the electrical part of the signal. The logical part is still good old UART, so from the Tiva point of view, you will still be writing to and reading bytes from the UART FIFO buffers. If you take advantage of the Tivaware library, go into chapter 31 of its manual, and understand things as UARTConfigSetExpClk() and UARTCharPut().

    If you don't yet understand the electric signals of serial communication, experiment with them a bit further. Get a standard "old" PC and try to implement a simple program to send/read more commom RS232 communication, and only then move on. This, of course, after you are able to create a project in whatever development platform you elected and get an led to blink using your own code.

    After that, RS485 communication will be clear and simple.

    Happy development!