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-example

Other Parts Discussed in Thread: TM4C123GH6PM

Hi,

To check uart_echo example, what are the connections need to be made? and how the texts will display in hyperterminal ?

  • I am using TM4C123GH6PM microcontroller, ccs6 with 5.0.4 compiler.
  • Hello Mary,

    The connection is the USB connection via the debugger. The uart_echo reflects what you type.

    Regards
    Amit
  • Hi Amit,
    I didn't get any display on hyper terminal. Am i need to change any settings?
  • Hello Mary

    Debug 101

    1,. Check the PC Device Manager is able to see a Serial COM Port and get the Port Number.
    2. Open a terminal and set it to the same Port Number as PC, with 115200, 8N1 format.
    3. Connect a Scope on the TX and RX lines of UART. Scope to see if you are able to send the data and the program is echo-ing it back

    Regards
    Amit
  • Hi Amit,
    PC COM port have 9600 bits per sec. Am I need to change that settings? and
    "Connect a Scope on the TX and RX lines of UART"
    PA0 and PA1 pins are internal pins. How could I connect that lines to an oscilloscope? Am I misunderstood anything?
  • Hello Mary,

    The UART echo example is 115200 bps, so you must change it. Also ensure that the COM port number matches that on the Console Application (Teraterm or PuTTy or RealTerm).

    PA0 and PA1 are available to probe as UTX and URX. You would need to look for it "carefully" in the schematic.

    Regards
    Amit
  • Hi Amit,
    I have changed the settings to 115200bps. And COM1 port is selected in hyperlink. Yet I didn't have any dispaly. I don't have scope, how can i test that? My PC has Windows 7.
  • Hi Amit,
    I have changed the settings to 115200bps. And COM5 port (specific port) is selected in hyperlink. And now

    "Enter text:"  is not displayed.

    whatever I typed in the keyboard displayed in hyperlink and led blinks at the time. But how can i know the text is transmitted and recieved through controller? and may i know the expected output format of the example?

  • Hello Mary

    The LED blinking is indicative that the console application "may' be working, but something else is not working well in the installer of the same. The input and output format is described in the application's readme.txt.

    Would suggest using TeraTerm and trying removing power to the board and restarting it again.

    Regards
    Amit
  • Hi Amit,
    Thank you. I can recieve the text in hyperterminal. And how can test that the text is transmitted and recieved through controller? because if type ABC then that displayed as
    Enter text: ABC
  • Hello Mary

    The uart_echo example sends back the same data. To be certain and to be able to modify the data, in the interrupt handler change the while loop to read the data and do a case conversion using subtraction of the difference of upper and lower case and then send the modified data back

    Regards
    Amit

  • Hi Amit,
    I tested the changes what you have suggested. Now I understood the process. Thank you for your valuable suggestions.
  • Hi Amit,
    I have a new doubt. How "void UARTIntHandler(void) " function invoked (without explicit function call) when an interrupt occurs?
  • Hello Mary,

    Please look at the startup_ccs.c file!!!

    Regards
    Amit
  • Hi Amit,Thank you. I found that.
  • Hi Amit,I use the following code to measure frequency deviation.
    #include <stdint.h>#include <stdbool.h>#include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"#include "inc/hw_nvic.h"#include "inc/hw_types.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/systick.h"
    #include "driverlib/uart.h"#include "utils/uartstdio.h"
    #include "driverlib/timer.h"
    #define GPIO_PORTF_DATA_R (*((volatile uint32_t *)0x400253FC))
    #define GPIO_PORTF_PUR_R (*((volatile uint32_t *)0x40025510))
    #define GPIO_PORTF_ICR_R (*((volatile uint32_t *)0x4002541C))#ifdef DEBUG
    void__error__(char *pcFilename, uint32_t ui32Line){}#endifint FallingEdges=0;
    volatile unsigned long Old_Count;volatile unsigned long New_Count=0;
    volatile unsigned long TimeCount;float frequency,freq,Time;
    void ConfigureUART(void){ ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    ROM_GPIOPinConfigure(GPIO_PA0_U0RX); ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    UARTStdioConfig(0, 115200, 16000000);}void PortFIntHandler(void){
    GPIO_PORTF_DATA_R |= 0x04; GPIO_PORTF_ICR_R = 0x10; // acknowledge flag4
    FallingEdges = FallingEdges + 1; if(FallingEdges==50){ Old_Count=New_Count;
    New_Count=ROM_TimerValueGet(TIMER0_BASE, TIMER_A); FallingEdges=0; }
    TimeCount=New_Count-Old_Count; Time=TimeCount/16000000; freq=1/Time;
    frequency=freq*50; UARTprintf("\nFrequency: %d\n",frequency);
    UARTprintf("\nFrequency Deviation: %s\n",(frequency<50) ? "Yes" : "No");}
    int main(void){
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    SysCtlDelay(3); ROM_TimerDisable(TIMER0_BASE,TIMER_A);
    ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC_UP);
    ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, 0x00FFFFFF);
    ROM_TimerEnable(TIMER0_BASE, TIMER_A);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlDelay(3);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_3|GPIO_PIN_2);
    GPIO_PORTF_PUR_R |= 0x10; // enable weak pull-up on PF4
    GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_4,GPIO_FALLING_EDGE);
    IntEnable(INT_GPIOF); GPIOIntEnable(GPIO_PORTF_BASE, GPIO_INT_PIN_4);
    ROM_FPULazyStackingEnable();
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    ConfigureUART(); UARTprintf("\033[2JFrequency Measurement:-\n");
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet()); ROM_SysTickEnable();
    ROM_IntMasterEnable(); while(1) { }}I always get,
    "Frequency Measurement:-"
    PortFIntHandler is not executed (checked with LED). I made changes in startup_ccs.c file for interuupt handler as like uart_echo example. What I need to change further? Thank you.
  • Hi Amit,I am using following code to check frequency deviation.
    #include <stdint.h>#include <stdbool.h>#include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"#include "inc/hw_nvic.h"#include "inc/hw_types.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/systick.h"
    #include "driverlib/uart.h"#include "utils/uartstdio.h"
    #include "driverlib/timer.h"
    #define GPIO_PORTF_DATA_R (*((volatile uint32_t *)0x400253FC))
    #define GPIO_PORTF_PUR_R (*((volatile uint32_t *)0x40025510))
    #define GPIO_PORTF_ICR_R (*((volatile uint32_t *)0x4002541C))#ifdef DEBUG
    void__error__(char *pcFilename, uint32_t ui32Line){}#endifint FallingEdges=0;
    volatile unsigned long Old_Count;volatile unsigned long New_Count=0;
    volatile unsigned long TimeCount;float frequency,freq,Time;void
    ConfigureUART(void){ ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    ROM_GPIOPinConfigure(GPIO_PA0_U0RX); ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    UARTStdioConfig(0, 115200, 16000000);}void PortFIntHandler(void){
    GPIO_PORTF_DATA_R |= 0x04; GPIO_PORTF_ICR_R = 0x10; // acknowledge flag4
    FallingEdges = FallingEdges + 1; if(FallingEdges==50){ Old_Count=New_Count;
    New_Count=ROM_TimerValueGet(TIMER0_BASE, TIMER_A); FallingEdges=0; }
    TimeCount=New_Count-Old_Count; Time=TimeCount/16000000; freq=1/Time;
    frequency=freq*50; UARTprintf("\nFrequency: %d\n",frequency);
    UARTprintf("\nFrequency Deviation: %s\n",(frequency<50) ? "Yes" : "No");}
    intmain(void){ SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); SysCtlDelay(3);
    ROM_TimerDisable(TIMER0_BASE,TIMER_A);
    ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC_UP);
    ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, 0x00FFFFFF);
    ROM_TimerEnable(TIMER0_BASE, TIMER_A);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlDelay(3);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_3|GPIO_PIN_2);
    GPIO_PORTF_PUR_R |= 0x10; // enable weak pull-up on PF4
    GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_4,GPIO_FALLING_EDGE);
    IntEnable(INT_GPIOF); GPIOIntEnable(GPIO_PORTF_BASE, GPIO_INT_PIN_4);
    ROM_FPULazyStackingEnable();
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
    SYSCTL_XTAL_16MHZ); ConfigureUART();
    UARTprintf("\033[2JFrequency Measurement:-\n");
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet()); ROM_SysTickEnable();
    ROM_IntMasterEnable(); ROM_IntMasterDisable(); while(1) { }}
    I always get,"Frequency Measurement:-"
    PortFIntHandler is not executed (checked with LED). I made changes in startup_ccs.c file for interuupt handler as like uart_echo example. What I need to change further? Thank you.
  • Hello Mary,

    Debug!!! So when you toggle Pin-4 of GPIO Port F, does the data register show the value 0 instead of 1 for Pin-4?

    Regards
    Amit
  • Hi Amit,

    The GPIO_DATA register have 0x00000010. Is any header files need to be changed.

  • Hello Mary,

    I meant to say that when you toggle the pin low and keep it low does the GPIO DATA register show 0 or 1 for the corresponding pin.

    Also please check what is the setting of the other registers. If you halt the program is still in the main loop or is it stuck in some other loop?

    Regards
    Amit
  • Hi Amit,
    When i didn't give any input to that pin, the register shows 1 for the corresponding pin.
    GPIO_DATA 0x00000010 GPIO_DIR 0x0000000C
    GPIO_IM 0x00000010 GPIO_DR2R 0x000000FF
    GPIO_PUR 0x00000010
    GPIO_DEN 0x0000001C GPIO_LOCK 0x00000001
    GPIO_CR 0x000000FE GPIO_AMSEL 0x00000000
    and other resiaters are 0x00000000.
    When the program halted program stuck in the main loop.
  • Hello Mary,

    And what was the value when an input of 0V (or GND) was done?

    Regards
    Amit
  • Hi Amit,

    Actually I need to measure frequency deviation of AC signal. For that initially I am working with pulse. Now I develop a code to check zero crossing of AC input. Here is my code.  I am giving input such that, the input goes to zero for every 0.02sec. And I am using TimerValueGet to get time period. But for every cycle the timer value varies (input fall to zero in 0.02 sec interval). Can you suggest what may be the error? Timer value mostly changes between 250000 to 310000. And one more thing, the value Time (Time=(TimeCount/320000);) mostly shows 0.0/1609.  Thank you so much for your help.

    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/hw_memmap.h"
    #include "driverlib/adc.h"
    #include "driverlib/gpio.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/adc.h"
    #include "inc/hw_types.h"
    #include "driverlib/fpu.h"
    #include "driverlib/debug.h"
    #include "driverlib/timer.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    
    #define GPIO_PA0_U0RX           0x00000001
    #define GPIO_PA1_U0TX           0x00000401
    
    volatile unsigned long Old_Count;
    volatile unsigned long New_Count=0;
    int FallingEdges=0;
    volatile unsigned long TimeCount;
    float Ans;
    float frequency;
    float freq;
    float Time;
    float Time2,freq2,frequency2;
    int Cycle=0;
    int Time1,Temp1,Time3,freq1,Temp2,freq3,frequency1,Temp3,frequency3;
    
    void
    ConfigureUART(void)
    {
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
        UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
        UARTStdioConfig(0, 115200, 16000000);
    }
    
    main(void) {
    
        uint32_t pui32ADC0Value[0];
    
        SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN| SYSCTL_XTAL_16MHZ);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    	SysCtlDelay(3);
    
    	TimerDisable(TIMER0_BASE,TIMER_A);
    	TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC_UP);
    	TimerLoadSet(TIMER0_BASE, TIMER_A, 0x00FFFFFF);
    	TimerEnable(TIMER0_BASE, TIMER_A);
        GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);
    
        ADCIntEnable(ADC0_BASE, 3);
        ADCSequenceDisable(ADC0_BASE, 3);
        ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
        ADCSequenceStepConfigure(ADC0_BASE, 3, 0,ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END);
    
        ConfigureUART();
    
        UARTprintf("\033[2JFrequency Measurement:-\n");
        ADCSequenceEnable(ADC0_BASE, 3);
    
        while (1) {
            ADCProcessorTrigger(ADC0_BASE, 3);
            while (!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    
            ADCIntClear(ADC0_BASE, 3);
            ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);
            Ans=(pui32ADC0Value[0]*3.3)/4095;
            UARTprintf("\npui32ADC0Value[0]:%d\n",pui32ADC0Value[0]);
    
            if (pui32ADC0Value[0]==0)
            {
            	Old_Count=New_Count;
            	New_Count=TimerValueGet(TIMER0_BASE, TIMER_A);
            	UARTprintf("\nCycles:%d\n",Cycle);
            	TimeCount=New_Count-Old_Count;
          	  Time=((float)TimeCount/320000);
          	  freq=1/Time;
          	  frequency=freq*50;
          	  //for float
          	  Time1=Time;
          	  Time2=Time*100000;
          	  Temp1=Time1*100000;
          	  Time3=Time2-Temp1;
    
          	freq1=freq;
          	freq2=freq*100000;
          	Temp2=freq1*100000;
          	freq3=freq2-Temp2;
    
          	frequency1=frequency;
          	frequency2=frequency*100000;
          	Temp3=frequency1*100000;
          	frequency3=frequency2-Temp3;
    
          	UARTprintf("\nAns:%d\n",Ans);
            UARTprintf("\nCycles:%d\n",Cycle);
          	UARTprintf("\nNew_Count:%d\n",New_Count);
          	UARTprintf("\nOld_Count:%d\n",Old_Count);
          	UARTprintf("\nTimeCount:%d\n",TimeCount);
          	UARTprintf("\nTime:%d\n",Time);
          	UARTprintf("\nTime:%d.%d\n",Time1,Time3);
          	UARTprintf("\nFrequency:%d.%d\n",freq1,freq3);
          	UARTprintf("\nFrequency:%d.%d\n",frequency1,frequency3);
    
            }
    
    }
    }
    
    

  • Hello Mary

    The condition of pui32ADC0Value being 0 can be problematic as the value captured may be not 0 but a few decimal points away. Rather use a less than condition lile

    if(pui32ADC0Value < 100)

    Regards
    Amit
  • Hi Amit,

    I tried that with "if (pui32ADC0Value<20)". Other values made more deviate in the measurement. And I got the measured frequency values for absolute 50Hz frequency input in terminal are:

    Freq:49.45384
    Freq:49.45109
    Freq:41.91323
    Freq:49.46454
    Freq:49.24365
    Freq:49.1525
    Freq:49.23228
    Freq:49.1795
    Freq:49.23137
    Freq:41.89633
    Freq:49.1690
    Freq:49.23683
    Freq:49.1555
    Freq:49.23804
    Freq:49.924
    Freq:49.45843
    Freq:49.789
    Freq:41.90565
    Freq:49.1570

    And I can't get the correct frequency. Why the timer value that much varies? What I need to change in the code to get the correct measure?

  • Hello Mary,

    How are you accomodating the timer roll over? Also why are you printing the ADC value and then reading the timer. A basic design rule is time critical readings must be done before any prints are done.

    Regards
    Amit
  • Hi Amit,
    Thank you so much. After removing the print function, it measures the correct value.
  • Hello Mary

    General thumb of rule, is when to make measurements which are time critical usage of prints and delays must be avoided

    Regards
    Amit