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/EK-TM4C123GXL: UART1(RS 485) Transmitting Data but Not Receiving !!!!

Part Number: EK-TM4C123GXL

Tool/software: Code Composer Studio

HI,

 I am working Communication protocol , Using UART1(RS 485) for communicating with external device. I have checked loop back , TX and RX configuration done successfully because getting loop back character. when i sending data to external device UART1 transmitting data successfully, External device HMI display the data which have received from UART1(TM4C123GXL).   If i am sending data through HMI , i couldnt get data in TM4C123gxl side. Last two days i hardly working for find this mistake,if any given solution its very helpful for me.

 Here i have my sending and receiving code:

//*****************************************************************************

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
unsigned char BUF1[100]={'S','N','G'};                       // Sending Data
unsigned char BUF2[100];
unsigned  int i;



#define RS485base GPIO_PORTA_BASE
#define MAX485_DE GPIO_PIN_6
#define MAX485_RE_NEG GPIO_PIN_7

//*******************************
//*****************************************************************************
   #ifdef DEBUG
   void
   __error__(char *pcFilename, uint32_t ui32Line)
   {
   }
   #endif

   //******************************
   void preTransmission();
   void postTransmission();

   //*****************************************************************************
   void UART0_put_char(const uint8_t pui8Buffer)
   {

       preTransmission();

           // Write the next character to the UART.
           //
       UARTCharPut(UART0_BASE, pui8Buffer);
       postTransmission();

   }

 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                                                                                                                                    //UART 1 Transmitting Function

   void uart1_put_char( uint8_t  BUF3 )
   {
       preTransmission();

       UARTCharPut(UART1_BASE, BUF3);
       postTransmission();

   }


//////////////////////////////                    //UART 1Recieving  Function
   void uart1_get_char()
   {
       postTransmission();

    unsigned char  j=0;

   while(ROM_UARTCharsAvail(UART1_BASE))


   {
      BUF2[j]=UARTCharGet(UART1_BASE);


      UART0_put_char(BUF2[j]);
      SysCtlDelay(2000);
   j++;
   preTransmission();
   }
   int k;
for(k=0;k<j;k++)
{
    BUF2[k]=0;
}
   }

   //////////////////////////////////////////////////////////////////////////////////////////////////////

   void preTransmission()
   {
       GPIOPinWrite(GPIO_PORTA_BASE, MAX485_RE_NEG,  MAX485_RE_NEG);
       GPIOPinWrite(GPIO_PORTA_BASE, MAX485_DE, MAX485_DE);


   }

   void postTransmission()
   {
       GPIOPinWrite(GPIO_PORTA_BASE, MAX485_RE_NEG, 0x00);
       GPIOPinWrite(GPIO_PORTA_BASE, MAX485_DE, 0x00);

   }


    void RS485enable()
    {

        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
               GPIOPinTypeGPIOOutput(RS485base, MAX485_DE|MAX485_RE_NEG);


    }




   //*****************************************************************************
   int main(void)
   {
      //unsigned char pui8Buffer;


       // Enable lazy stacking for interrupt handlers.  This allows floating-point
       // instructions to be used within interrupt handlers, but at the expense of
       // extra stack usage.
       //
       ROM_FPUEnable();
       ROM_FPULazyStackingEnable();

       //
       // Set the clocking to run directly from the crystal.
       //
       ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                          SYSCTL_XTAL_16MHZ);

       //
       // Enable the GPIO port that is used for the on-board LED.
       //
       ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

       //
       // Enable the GPIO pins for the LED (PF2).
       //
       ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

       //
       // Enable the peripherals used by this example.
       //
       ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
       ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);


       ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
       ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

       //
       // Enable processor interrupts.
       //
     //  ROM_IntMasterEnable();

       //
       // Set GPIO A0 and A1 as UART pins.
       //
       GPIOPinConfigure(GPIO_PA0_U0RX);
       GPIOPinConfigure(GPIO_PA1_U0TX);


       GPIOPinConfigure(GPIO_PB0_U1RX);
       GPIOPinConfigure(GPIO_PB1_U1TX);

       ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
       ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);



       //
       // Configure the UART for 115,200, 8-N-1 operation.
       //
       ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(),19200,
                               (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                                UART_CONFIG_PAR_NONE));

       ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 19200,
                                  (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                                   UART_CONFIG_PAR_NONE));
       RS485enable();

       // Loop forever echoing data through the UART.
       //

       GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_6, 0x00);
      GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7, 0x00);

       while(1)
       {
           uint32_t value=0;
           uint8_t i=0;

           for(i=0;i<6;i++)
           {
              uart1_put_char( BUF1[i]);                             // Transmitting Data

           }


           uart1_get_char();                                           // Receiving Data 

       }
   }


Serial Monitor Output window

  • Greetings,

    Feel your pain - yet some 'basic troubleshooting' is sure to aid both you & remote helpers.

    If what you report proves correct then there exist "usual suspects" - these should be the first to be investigated:

    • Your RS485 line driver enables its 'MCU Receive Side' only upon the proper & timely arrival of signal to the 'RE pin.'     Have you scoped this RE pin - along w/the incoming, RS485 data - and confirmed that the RE pin is properly driven - prior to the arrival of the RS485 signal's 'Start Bit?'    (and then remains stable throughout the remainder of the data byte(s)?)
    • It is normal/customary to have such RS485 line drivers ordered into 'Receive Mode' as their normal operating condition.    Order the line driver into 'Transmit Mode' only when & as required - and usually as briefly as possible.    Again your scope probing can effectively monitor & confirm this.
    • It 'cannot hurt' to employ an external "Pull-Up" resistor at UART_1's RX pin.  (*)    (sometimes - but not always - the line driver proves 'guilty' in this regard - especially when its 'RE pin' is being toggled)
    • During test/troubleshooting the use of (any) 'indirection' (i.e. buffers) is NOT recommended.    KISS directs 'Simple & Direct' - thus single byte transmissions/receptions - to eliminate (other) potential causes of failure!
    • And - even though your TX side (appears) to work - confirm that there is a 'solid & proper' Ground Connection between the HMI & your MCU board.

    Should you be w/out a scope - by slowing the baud rate (to ~300 - ~600 baud) if possible - you may enable 'monitoring Leds' to indicate the presence of the serial signal at (both) UART_1 RX & the RS485's differential signal pair.    (the scope proves incredibly helpful - especially when diagnosing serial data...)

    (*) Staff believes this to 'most likely' resolve your issue...