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.

UART RX problem. TM4C123G.

Other Parts Discussed in Thread: TM4C123GH6PM

Hello,

Guys, please help me. I trying modify TM4C123G LaunchPad Workshop workbook, UART topic, 12 lab first example code. Example code I tryed, work perfect. Below, its my modification, but it not working.. I'm writting letter D and else to computer program putty, but microcontroller led light don't shine..

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"

#define RED_LED   GPIO_PIN_1
#define BLUE_LED  GPIO_PIN_2
#define GREEN_LED GPIO_PIN_3

int main(void) {
uint16_t readvalue;

SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    UARTCharPut(UART0_BASE, 'E');
    UARTCharPut(UART0_BASE, 'n');
    UARTCharPut(UART0_BASE, 't');
    UARTCharPut(UART0_BASE, 'e');
    UARTCharPut(UART0_BASE, 'r');
    UARTCharPut(UART0_BASE, ':');
    UARTCharPut(UART0_BASE, ' ');

while(UARTCharsAvail(UART0_BASE))
     {
        while(UARTCharGet(UART0_BASE)!=0x44) // 0x44 equal to D on the keybord.
        {
        }

        readvalue = UARTCharGet(UART0_BASE);
        if(readvalue==0)
        {
        GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, 0x00);
        SysCtlDelay(1000000);
        }
        else
        {
        GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, RED_LED);
        SysCtlDelay(1000000);
        }

    }

  • Hello Gytis,

    The issue is here. Since there are no characters it does not enter the while loop.

    while(UARTCharsAvail(UART0_BASE))

    Regards

    Amit

  • Thank you for your answer Amit! I try this way, but still not working...

    while(1) {

         while(UARTCharsAvail(UART0_BASE))
         {
            while(UARTCharGet(UART0_BASE)!=0x44) // 0x44 equal to D.
            {
            }

            readvalue = UARTCharGet(UART0_BASE);
            if(readvalue==0)
            {
            GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, BLUE_LED);
            SysCtlDelay(1000000);
            GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, 0x00);
            }
            else
            {
            GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, RED_LED);
            SysCtlDelay(1000000);
            GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, 0x00);
            }
        }
    }
    }

    But if i write this way, microcontroller led turn on pressed every button even D (which is 0x44).. so it seems that  is not while loop problem.

    while(1) {

         while(UARTCharsAvail(UART0_BASE))
         {
            while(UARTCharGet(UART0_BASE)!=0x44) // 0x44 equal to D.
            {
                GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, BLUE_LED);
                SysCtlDelay(1000000);
                GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, 0x00);
            }
        }
    }

     

  • Hello Gytis,

    UARTCharGet returns the 32-bit value of the DR register. This includes the Error Flag. It is possible one of the Error flags is being set. You would need to check which error flag in bits 11:8 is being set.

    Regards

    Amit

  • Yes, thank you! now it try with UART interrupt.

  • One more question.

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "inc/tm4c123gh6pm.h"
    #include "driverlib/debug.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "inc/hw_gpio.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    #include "inc/hw_ints.h"
    #include "driverlib/interrupt.h"

    void UARTIntHandler(void)
    {
        uint32_t ui32Status;
        ui32Status = UARTIntStatus(UART0_BASE, true); //get interrupt status
        UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts

        while(UARTCharsAvail(UART0_BASE)) //loop while there are chars
        {


            if(UARTCharGet(UART0_BASE)==0x44) // 0x44 equal to D.
            {
                GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
                SysCtlDelay(100000);
                GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0x00);
            }
        }

    }
    int main(void) {

        SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);

        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //enable GPIO port for LED
        GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); //enable pin for LED PF2

        UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

        UARTStdioConfig(0, 115200, 16000000);

        IntMasterEnable(); //enable processor interrupts
        IntEnable(INT_UART0); //enable the UART interrupt
        UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); //only enable RX and TX interrupts

        UARTprintf("Welcome to the Tiva C Series TM4C123G LaunchPad!\n");

        while (1)
        {
        }
    }

    uart interrupt work nice until I add these two marked lines..

    writting error's:

    ">#10234-D</a>  unresolved symbols remain    lab12

    #10010 errors encountered during linking; "lab12.out" not built    lab12     


    unresolved symbol UARTStdioConfig, first referenced in ./main.obj    lab12             C/C++ Problem

    unresolved symbol UARTprintf, first referenced in ./main.obj    lab12             C/C++ Problem

    How I could solve these error's?

  • Hello Gytis

    Please add the uartsdio.c to the project

    Regards

    Amit

  • #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "inc/hw_ints.h"
    #include "driverlib/interrupt.h"
    #include "utils/uartstdio.h"

     static char g_cInput[6];
     static char g_string[6] = "hello";

    void UARTIntHandler(void)
    {
        uint32_t ui32Status;
        ui32Status = UARTIntStatus(UART0_BASE, true); //get interrupt status
        UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts

            while(UARTPeek('\r') != -1)
            {
                UARTgets(g_cInput,sizeof(g_cInput));
            }

            if(g_cInput == g_string)
            {
                GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //blink LED
                SysCtlDelay(SysCtlClockGet() / (1000 * 3)); //delay ~1 msec
                GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
            }
    }

    int main(void) {

        SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

        UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

        IntMasterEnable();
        IntEnable(INT_UART0);
        UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
        GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);


        UARTStdioConfig(0, 115200, 16000000);

        UARTprintf("Welcome to the Tiva C Series TM4C123G LaunchPad!\n");


        while (1)
        {
            //if (UARTCharsAvail(UART0_BASE)) UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
        }

    }

    Something with this code is wrong.. It's don't work currectly.. I writting word "hello" and enter button to microcontroller with putty program.

  • Gytis,

    Were you sucessfull in running the second part of lab12 with the added interupt code?  I am having trouble gettting this to run.  It immediately goes to the interupt fault loop.  I would appreciate any ideas on how to determine what is causing this.

     

    Chip

  • Hi Chip,

          Provide your code so others can review it, including startup file.

          Also it would be much better if you make a new post regarding your question.

    -kel

  • Hello Gytis,

    Please remove the second UART Coniguration UARTStdioConfig(0, 115200, 16000000); The code has already configured UART based on the System Clock Frequency and the second configuration is changing the Baud Rate incorrectly.

    Regards,

    Amit