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.

CCS/TM4C1294NCPDT: UART TTL to RS 485 Protocol

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: SN65HVD1782, EK-TM4C1294XL

Tool/software: Code Composer Studio

Hi

Can anyone please help on how can I convert my UART TTL to RS 485 for my application. I have knowledge that I need an enable pin to transmit my message but how should I configure the pin for the microcontroller. 

Code to do the same would help a lot.

Thank You in Advance.

  • Hi Charles.

    Thanks for your reply. The enable pin I am talking about is the one which enables the transmission to the RS 485 using SN65HVD1782. But my query is how can I configure the pins of microcontroller TM4C1294NCPDT using Code Composer Studio to do so.

    And also if not then can I use the RTS pin of the micro-controller and connect it to the DE, RE of the RS485?

  • Hi,

      Can you not use a GPIO pin to drive the enable pin?

  • Hello Charles,

    Yes, I can use a GPIO pin to enable the transmission. But I am not able to do that, so if you have a demo code on how to change a GPIO pin to act as an enable pin for RS 485 would really help my application.

    Thanks in advance.

  • Hi Nagasai,

      GPIO is quite simple. You can reference the TivaWare hello, blinky or project0 to get some ideas on how to use the GPIO pin. Below is the code snippet from the blink example. 

    #define USER_LED1  GPIO_PIN_0
    #define USER_LED2  GPIO_PIN_1
    
    //*****************************************************************************
    //
    // The error routine that is called if the driver library encounters an error.
    //
    //*****************************************************************************
    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line)
    {
    }
    #endif
    
    //*****************************************************************************
    //
    // Main 'C' Language entry point.  Toggle an LED using TivaWare.
    //
    //*****************************************************************************
    int
    main(void)
    {
        uint32_t ui32SysClock;
    
        //
        // Run from the PLL at 120 MHz.
        //
        ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN |
                                           SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);
    
        //
        // Enable and wait for the port to be ready for access
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
        while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION))
        {
        }
    
        //
        // Configure the GPIO port for the LED operation.
        //
        GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, (USER_LED1|USER_LED2));
    
        //
        // Loop Forever
        //
        while(1)
        {
            //
            // Turn on the LED
            //
            GPIOPinWrite(GPIO_PORTN_BASE, (USER_LED1|USER_LED2), USER_LED1);
    
            //
            // Delay for a bit
            //
            SysCtlDelay(ui32SysClock/6);
    
            //
            // Turn on the LED
            //
            GPIOPinWrite(GPIO_PORTN_BASE, (USER_LED1|USER_LED2), USER_LED2);
    
            //
            // Delay for a bit
            //
            SysCtlDelay(ui32SysClock/6);
        }
    }

  • Dear Sir,

    Sorry for the late reply. 

    I tried to implement functions which Outputs HIGH a GPIO pin when I start transmission and and makes it LOW when transmission is done. But the problem is where do I call these functions so that I get data at RS485 Level.

    I attached the screenshot of the functions created. I also enabled ,configured the GPIO PB5. Can you please suggest where should I call these functions.

    Thanks in Advance.

  • What is the purpose that you need the enable pin? Can you elaborate a bit? I don't know about your system design. If you simply need to use a GPIO as an enable pin then why wouldn't you enable the pin before start the UART transmission? Are you not calling the UARTCharPut to transmit data? I would have thought that you enable the pin before you call the UARTCharPut. As far as how far ahead the enable pin needs to be active before the UART transmission starts is timing question you need to find out yourself. 

     As far as I know the RS485 is a standard that specifies differential signaling on two lines rather than single-ended with a voltage referenced to ground like that of the UART. The difference is at the electrical level, not protocol level. See below.

    https://www.electronicdesign.com/what-s-difference-between/what-s-difference-between-rs-232-and-rs-485-serial-interfaces

    https://www.ftdichip.com/Support/Documents/TechnicalNotes/TN_111%20What%20is%20UART.pdf

  • Dear Sir,

    Yes sir, I know, I have to HIGH the enable pin before transmission and disable it after transmission. But in the example code of s2e (as the application I need is an Ethernet to Serial Converter where the Output serial is RS485),  queues and scheduling is being used, so I am not able to know where I should call the enable and disable functions. I couldn't find either where the UARTCharPut function is being called in the main function and where the function is actually defined.

    Please help as I am new to this kind of coding.

    Thank You.

  • Hi,

      First of all, you never mentioned you are doing a Ethernet to Serial application referencing enet_s2e. Please look for the UARTChaPut in the serial_task.c file if you are using the enet_s2e example. You need to play around to find the best place to activate your enable pin. I will strongly suggest you start with a simple UART example and know how it will work in your system and where would you place the enable pin before you venture to the s2e which is a much complicated application. Once you figure out how you will activate the enable pin relative to the UART transactions then you can later migrate to the s2e. You can find the UART examples in the TivaWare under <TivaWare_Install>/examples/boards/ek-tm4c1294xl/uart_echo.

  • Dear Charles,

    Thanks a lot for the advice. I will try to do as you said and test my application.