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.

UART0 Connection

Hi

I am using The evaluation board TM4C123GXL. I want to connect the UART0 to external UART device I am not quite sure how to do it..

I tried connecting the device to the Rx and Tx pin in the TIVA board but it did not work..

this happens only for UART0 for other UART it works fine.. 

Thanks

  • Does not UART0 connect directly to the on-board ICDI MCU - which defeats your objective?     (due to signal contention between the ICDI and external UART device)

    And - should you "break" that UART0 <-> ICDI connection - how then will you debug & program your board?

    As always - your "external UART device" is undefined - yet it must generate & accept signal levels compatible with your TM4C MCU.     (i.e. must not be RS232 levels unless you add suitable RS232 line drivers)

    You've many other UARTs from which to choose - your choice of UART0 - may not be appropriate...

  • so What if I connect RS232 devices without line drivers

    and what is line drivers
  • Sivaram SR said:
    so What if I connect RS232 devices without line drivers?  

    Perhaps results (similar) to crossing a busy city street (in the middle) on foot - without first looking!     Not good - in either case.

    Your use of Google seeking RS232 will describe RS232 "signal levels" and the "line-driver" ICs - which convert between the relatively low MCU levels and those employed by "true" RS232 devices.     RS232 signal levels may swing as high as 12-15V - must be reduced prior to introduction to any MCU or logic IC.

    Resist all temptation to "directly connect" any external RS232 device to your MCU!      Most always such will damage your MCU!

    As your initial post revealed (some) success w/an external UART - there is "hope" that that external device did NOT operate with full/real RS232 levels.     Always best to check and confirm FIRST - prior to joining any external device - to your MCU!

  • Thanks Ok i have the line driver the device is Rs232 type..

    still the device does not work with any other UART other that UART1

    pls help me with this
  • I fly in moments - this is most likely a UART set-up issue or a limitation imposed by your "standard I/O" library. (impacts higher numbered UARTs)
    Posting your code will enable others to best assist - diagnosis "blind" is not noted for success!
  • #include <stdbool.h>
    #include <stdint.h>
    #include "inc/hw_i2c.h"
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/gpio.h"
    #include "driverlib/i2c.h"
    #include "driverlib/ssi.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "driverlib/adc.h"
    #include "utils/uartstdio.h"
    #include "inc/hw_nvic.h"

    /*

    Action Command

    1) Reset '0'
    2) Core Temp '1' This sends the temp data back to CDMS via I2C
    3) SPI Test '2' Sends '1' if test is OK or '0'
    */
    #define NUM_SSI_DATA 3
    #define SLAVE_ADDRESS 0x5C
    int32_t g_ui32DataRx;
    int32_t g_ui32DataTx;
    uint32_t Pia[3];
    uint32_t pui32DataTx[NUM_SSI_DATA];
    uint32_t pui32DataRx[NUM_SSI_DATA];
    static bool g_bIntFlag = false;
    int counter,result;


    void Reset(void)
    {
    //SysCtlReset();
    HWREG(NVIC_APINT) = NVIC_APINT_VECTKEY | NVIC_APINT_SYSRESETREQ;
    }

    int uc_core_temp(void)
    {

    uint32_t pui32ADC0Value[1];
    uint32_t ui32TempValueC;
    //uint32_t ui32TempValueF;

    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1);


    ADCProcessorTrigger(ADC0_BASE, 3);
    while(!ADCIntStatus(ADC0_BASE, 3, false))
    {
    }
    ADCIntClear(ADC0_BASE, 3);
    ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);
    ui32TempValueC = (1475 - ((2250 * pui32ADC0Value[0])/4096)) / 10;
    //ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;

    /* while(!(I2CSlaveStatus(I2C3_BASE) & I2C_SLAVE_ACT_TREQ))
    {
    }
    I2CSlaveDataPut(I2C3_BASE,ui32TempValueC);
    SysCtlDelay(SysCtlClockGet()/100);
    */
    //SysCtlPeripheralReset(SYSCTL_PERIPH_I2C3);
    //UARTprintf("Temperature = %3d*C or %3d*F\r", ui32TempValueC,
    // ui32TempValueF);

    return ui32TempValueC;
    }

    void SPI_Enable(void)
    {
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinConfigure(GPIO_PA2_SSI0CLK);
    GPIOPinConfigure(GPIO_PA3_SSI0FSS);
    GPIOPinConfigure(GPIO_PA4_SSI0RX);
    GPIOPinConfigure(GPIO_PA5_SSI0TX);
    GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 |
    GPIO_PIN_2);
    SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
    SSI_MODE_MASTER, 1000000, 16);
    SSIEnable(SSI0_BASE);
    }


    void UARTIntHandler(void)
    {

    uint32_t ui32Status;
    char LED;
    //
    // Get the interrrupt status.
    //
    ui32Status = UARTIntStatus(UART1_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    UARTIntClear(UART1_BASE, ui32Status);

    LED = UARTCharGet(UART1_BASE);

    UARTprintf("%c \n",LED);



    }



    /*

    SPI_Test
    0 = Ok
    1 = Send fault
    2 = Recieve fault

    */

    int SPI_Test(void)
    {
    int Test;
    while(SSIDataGetNonBlocking(SSI0_BASE, &pui32DataRx[0]))
    {
    }
    Pia[0] = 's';
    pui32DataRx[0] = '0' ;
    pui32DataTx[0] = 's' ;
    pui32DataTx[0] &= 0x00FF;

    SSIDataPut(SSI0_BASE, pui32DataTx[0]);
    while(SSIBusy(SSI0_BASE))
    {

    if(Test == 200000)
    {
    result = 1 ;
    break;
    }
    Test++;

    }

    SSIDataGet(SSI0_BASE, &pui32DataRx[0]);
    pui32DataRx[0] &= 0x00FF;
    SysCtlDelay(SysCtlClockGet()/3);
    if(pui32DataRx[0] == pui32DataTx[0])
    {
    result = 0;
    }
    else
    {
    result = 1;
    }
    UARTprintf("'%c' ", pui32DataRx[0]);

    return result;
    }


    void
    ConfigureUART(void)
    {
    //
    // Enable GPIO port A which is used for UART0 pins.

    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1);
    SysCtlDelay(SysCtlClockGet()/1000);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0);

    // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

    //
    // Configure the pin muxing for UART0 functions on port A0 and A1.

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    // Enable pin PC6 for UART3 U3RX
    //
    GPIOPinConfigure(GPIO_PB0_U1RX);
    GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_1);

    //
    // Enable pin PC7 for UART3 U3TX
    //
    GPIOPinConfigure(GPIO_PB1_U1TX);
    GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_1);
    //GPIOPinConfigure(GPIO_PC6_U3RX);
    //GPIOPinConfigure(GPIO_PC7_U3TX);

    //
    // Enable UART0 so that we can configure the clock.
    //
    //SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);

    //
    // Use the internal 16MHz oscillator as the UART clock source.
    //
    UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);

    //
    // Select the alternate (UART) function for these pins.

    //GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);

    //
    // Initialize the UART for console I/O.
    //
    UARTStdioConfig(1, 115200, 16000000);

    //UARTFlowControlSet(UART1_BASE,UART_FLOWCONTROL_NONE);
    IntEnable(INT_UART1);
    UARTFIFODisable(UART1_BASE);
    UARTIntEnable(UART1_BASE, UART_INT_RX );
    UARTFIFOLevelSet(UART1_BASE,UART_FIFO_TX1_8,UART_FIFO_RX1_8);
    }


    void
    I2C0SlaveIntHandler(void)
    {
    int error=0,error1=0;
    I2CSlaveIntClear(I2C3_BASE); // Clearing the interrupt
    IntMasterDisable();


    g_ui32DataRx = I2CSlaveDataGet(I2C3_BASE); // Data Read from Master

    if(g_ui32DataRx == 0)
    {
    Reset();
    error1++;
    }

    else if(g_ui32DataRx == 1)

    {
    g_ui32DataTx = uc_core_temp();
    error1++;
    }

    else if(g_ui32DataRx == 2)
    {
    SPI_Enable();
    g_ui32DataTx = SPI_Test();
    error1++;
    }
    //I2CSlaveIntDisable(I2C3_BASE);

    while(!(I2CSlaveStatus(I2C3_BASE) & I2C_SLAVE_ACT_TREQ))
    {
    if(error1 == error)
    {
    // error1++;
    break;
    }
    }
    error++;
    I2CSlaveDataPut(I2C3_BASE,g_ui32DataTx);
    SysCtlDelay(SysCtlClockGet()/100);

    //I2CSlaveIntEnable(I2C3_BASE);
    IntMasterEnable();
    UARTprintf("\n Slave Interrupt Received!\n");

    UARTprintf(" Received: '%d'\n\n", g_ui32DataRx);

    g_bIntFlag = true;

    }

    void
    main(void)
    {
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1);
    SysCtlDelay(SysCtlClockGet()/1000);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0);


    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
    SYSCTL_XTAL_16MHZ); // Clock set at 80Mhz


    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    GPIOPinConfigure(GPIO_PD0_I2C3SCL);
    GPIOPinConfigure(GPIO_PD1_I2C3SDA);
    GPIOPadConfigSet(GPIO_PORTD_BASE,GPIO_PIN_1,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_OD); // set the pin as open drain


    GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
    GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);

    I2CSlaveIntEnableEx(I2C3_BASE, I2C_SLAVE_INT_DATA); // Slave Interrupt configure
    IntMasterEnable();
    IntEnable(INT_I2C3);

    I2CSlaveEnable(I2C3_BASE);
    I2CSlaveInit(I2C3_BASE, SLAVE_ADDRESS); // Slave configure

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_TS | ADC_CTL_IE |
    ADC_CTL_END);
    ADCSequenceEnable(ADC0_BASE, 3);
    ADCIntClear(ADC0_BASE, 3);


    ConfigureUART();

    while(1)
    {

    }

    }



    here is the code