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.

TM4C1294NCPDT: How to change baud rate of serial terminal during run time using UART???

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

I was trying UART on the EK-TM4C1294XL. Basically I have a task to write code
for uart. On uart terminal, menu will get printed in which user will have a option
to choose specific settings for the serial terminal according to there requirement.
So user can be able to change baud rate during run time. Here first thing need to check is
whether user entered right baud rate or not.

We have "UARTCharGet(UART0_BASE)" api so using this we can
get data from user but if user entered "9600" and it will come like this
9->0x39
6->0x36
0->0x30
0->0x30

so one by one bit will get stored into the buffer.

Now the question arises that how we can pass the new baud rate which is entered by user to the "UARTConfigSetExpClk"

Any help will be really appreciated!!

  • Hi,

      You can write your own program to convert from ascii to integer or you can try the C library function atoi (ascii to integer)? Below is example.

    Description

    The C library function int atoi(const char *str) converts the string argument str to an integer (type int).

    Declaration

    Following is the declaration for atoi() function.

    int atoi(const char *str)

    Parameters

    • str − This is the string representation of an integral number.

    Return Value

    This function returns the converted integral number as an int value. If no valid conversion could be performed, it returns zero.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main () {
       int val;
       char str[20];
       
       strcpy(str, "98993489");
       val = atoi(str);
       printf("String value = %s, Int value = %d\n", str, val);
    
       return(0);
    }

  • Hello Charles

    Thank you for the suggestion.

    Regards,

    Omkar

  • Hello Charles

    I tried to change the UART configuration but its not changing. Here I'm attaching code below.

    #include <stdint.h>
    #include <stdbool.h>
    #include <stdio.h>
    
    #include "TM4C129.h"                    // Device header
    #include "RTE_Components.h"             // Component selection
    
    #include "FreeRTOSConfig.h"             // ARM.FreeRTOS::RTOS:Config
    #include "FreeRTOS.h"                   // ARM.FreeRTOS::RTOS:Core
    #include "task.h"                       // ARM.FreeRTOS::RTOS:Core
    #include "timers.h"                     // ARM.FreeRTOS::RTOS:Timers
    
    
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/debug.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    //*****************************************************************************
    BaseType_t ret;
    
    #define NUM_UART_DATA    100
    //#define NUM_UART_DATA    4
    
    extern void UARTSend(uint32_t ui32UARTBase, const uint8_t *pui8Buffer, uint32_t ui32Count);
    void Task1( void *pvParameters );
    //****************************************************************************
    //
    // System clock rate in Hz.
    //
    //****************************************************************************
    
    uint32_t ui32SysClock;
    uint8_t ui8DataTx[NUM_UART_DATA];
    uint8_t ui8DataRx[NUM_UART_DATA];
    uint32_t ui32index;
    char x,y=0,z;
    uint32_t len;
    
    struct settings{
    	int baud_rate,Bits,Stop_Bits;
    	char parity;
    }setting;
    //*****************************************************************************
    //
    // This example demonstrates how to send a string of data to the UART.
    //
    //*****************************************************************************
    int main(void)
    {
    	
        ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                               SYSCTL_OSC_MAIN |
                                               SYSCTL_USE_PLL |
                                               SYSCTL_CFG_VCO_240), 120000000);
    	
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7);
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);     
    
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
        MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        UARTLoopbackEnable(UART7_BASE);	
    	
        MAP_UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 115200,
                                (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                                 UART_CONFIG_PAR_NONE));
    
    
          /********************** MAIN APPLICATION CODE ****************************/
    
          //TASK creation
          ret = xTaskCreate(Task1,"Transmit_Receive",240,NULL,tskIDLE_PRIORITY + 1UL,NULL );
          configASSERT(ret);
    
    
          vTaskStartScheduler();
    
        //
        // Idle Task
        //
        while(1)
        {
        }
    }
    
    
    void Task1( void *pvParameters )
    {
      UARTSend(UART0_BASE, (uint8_t *)"\n************$$Tapa ullekhaka$$************",strlen("\n************$$Tapa ullekhaka$$************"));
    	UARTSend(UART0_BASE, (uint8_t *)"\nHardware                 : EK-TM4C1294XL",strlen("\nHardware                 : EK-TM4C1294XL"));	
    	UARTSend(UART0_BASE, (uint8_t *)"\nSoftware Version         : 1.0\n",strlen("\nSoftware Version         : 1.0\n"));
    	UARTSend(UART0_BASE, (uint8_t *)"*****************************************\n",strlen("*****************************************\n"));
    	UARTSend(UART0_BASE, (uint8_t *)"\nSelect one of the options from the below",strlen("\nSelect one of the options from the below"));	
    
    	UARTSend(UART0_BASE, (uint8_t *)"\nSerial Port Settings-> s",strlen("\nSerial Port Settings-> s"));
    	UARTSend(UART0_BASE, (uint8_t *)"\nExit                -> e",strlen("\nExit                -> e"));	
    	UARTSend(UART0_BASE, (uint8_t *)"\nRead Data           -> r",strlen("\nRead Data           -> r"));
    	UARTSend(UART0_BASE, (uint8_t *)"\nDefault             -> d",strlen("\nDefault             -> d"));
    	while(1)
    	{
    	y = UARTCharGet(UART0_BASE);
    		
    	if(y == 's' || y == 'S')
    	{
    
    	 UARTSend(UART0_BASE, (uint8_t *)"\n**************Serial Port Settings**************",strlen("\n**************Serial Port Settings**************"));	
    													 UARTSend(UART0_BASE, (uint8_t *)"\nEnter the (Baud Rate)-(No of bits)-(Parity)-(Stop Bits) one by one",strlen("\nEnter the (Baud Rate)-(No of bits)-(Parity)-(Stop Bits) one by one"));	
    													 
    													 UARTSend(UART0_BASE, (uint8_t *)"\nChoose suitable baud rate from the above list:",strlen("\nChoose suitable baud rate from the above list:"));
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(1):9600",strlen("\n(1):9600"));		
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(2):14400",strlen("\n(2):14400"));	
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(3):19200",strlen("\n(3):19200"));	
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(4):38400",strlen("\n(4):38400"));	
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(5):56000",strlen("\n(5):56000"));	
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(6):57600",strlen("\n(6):57600"));	
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(7):115200",strlen("\n(7):115200"));			
    															
    														z = UARTCharGet(UART0_BASE);
    		
    													if(z=='1'||z=='2'||z=='3'||z=='4'||z=='5'||z=='6'||z=='7')
    													{
    														UARTSend(UART0_BASE, (uint8_t *)"\ncorrect choise",strlen("\ncorrect choise"));
    																		switch(z)
    																		{
    																			case 1: setting.baud_rate = 9600;
    																		break;
    																			case 2 : setting.baud_rate = 14400;
    																		break;
    																			case 3: setting.baud_rate = 19200;
    																			break;
    																			case 4: setting.baud_rate = 38400;
    																		break;
    																			case 5: setting.baud_rate = 56000;
    																		break;
    																			case 6: setting.baud_rate = 57600;
    																		break;	
    																			case 7: setting.baud_rate = 115200;
    																		break;			
    																		}			
    													}
    														else
    														{
    																	UARTSend(UART0_BASE, (uint8_t *)"\nerror",strlen("\nerror"));
    														}
    														
    													 UARTSend(UART0_BASE, (uint8_t *)"\nChoose suitable Data Bits from the above list:",strlen("\nChoose suitable Data Bits from the above list:"));
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(1):7-Bit",strlen("\n(1):7-Bit"));		
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(2):8-Bit",strlen("\n(2):8-Bit"));
    														
    															z = UARTCharGet(UART0_BASE);		
    														
    														if(z == '1' || z == '2')
    														{
    														UARTSend(UART0_BASE, (uint8_t *)"\ncorrect choise",strlen("\ncorrect choise"));
    																	switch(z)
    																	{
    																		case 1: setting.Bits = UART_CONFIG_WLEN_7;
    																	break;
    																		case 2 : setting.Bits = UART_CONFIG_WLEN_8;
    																	break;
    																	}
    														}
    														else
    														{
    																	UARTSend(UART0_BASE, (uint8_t *)"\nerror",strlen("\nerror"));
    														}
    														
    													 UARTSend(UART0_BASE, (uint8_t *)"\nChoose suitable Parity option from the above list:",strlen("\nChoose suitable Parity option from the above list:"));
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(1):None",strlen("\n(1):None"));		
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(2):Even",strlen("\n(2):Even"));
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(3):Odd",strlen("\n(2):Odd"));	
    												       
    														z = UARTCharGet(UART0_BASE);		
    														
    														if(z == '1' || z == '2')
    														{
    														UARTSend(UART0_BASE, (uint8_t *)"\ncorrect choise",strlen("\ncorrect choise"));
    																switch(z)
    																{
    																	case 1: setting.parity = UART_CONFIG_PAR_NONE;
    																break;
    																	case 2 : setting.parity = UART_CONFIG_PAR_EVEN;
    																break;
    																	case 3 : setting.parity = UART_CONFIG_PAR_ODD;
    																break;
    																}			
    													}
    														else
    														{
    																	UARTSend(UART0_BASE, (uint8_t *)"\nerror",strlen("\nerror"));
    														}
    
    													 UARTSend(UART0_BASE, (uint8_t *)"\nChoose suitable No of stop Bits from the above list:",strlen("\nChoose suitable No of stop Bits from the above list:"));
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(1):1 Stop Bit",strlen("\n(1):1 Stop Bit"));		
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(2):2 Stop Bit",strlen("\n(2):2 Stop Bit"));
    														
    															z = UARTCharGet(UART0_BASE);		
    														if(z == '1' ||z == '2')
    														{
    																	switch(z)
    																	{
    																		case 1: setting.Stop_Bits = UART_CONFIG_STOP_ONE;
    																	break;
    																		case 2 : setting.Stop_Bits = UART_CONFIG_STOP_TWO;
    																	break;			
    																		
    														}
    														MAP_UARTConfigSetExpClk(UART0_BASE, ui32SysClock, setting.baud_rate,
    																										(setting.Bits |setting.Stop_Bits |
    																										 setting.parity));
    													}		
    															else
    															{
    																	UARTSend(UART0_BASE, (uint8_t *)"\nerror",strlen("\nerror"));				
    															}
    }
    														
    	else if(y == 'e' || y == 'E')
    	{
    	 UARTSend(UART0_BASE, (uint8_t *)"\n**************Exit**************",strlen("\n**************Exit**************"));			
    	}
    	
    	else if(y == 'r' || y =='R')
    	{
    	 UARTSend(UART0_BASE, (uint8_t *)"\n**************Read Data**************",strlen("\n**************Read Data**************"));					
    	 UARTSend(UART0_BASE, (uint8_t *)"\n(Press '@' on the keyboard when you done writing on the terminal)",strlen("\n(Press '@' on the keyboard when you done writing on the terminal)"));	
    	 UARTSend(UART0_BASE, (uint8_t *)"\nNow Enter The Characters :",strlen("\nNow Enter The Characters :"));
    
    		//*****************************************************************************
    		//
    		// to write data during programming 
    		//
    		//*****************************************************************************
    		//	
    		//    //
    		//    // Prepare data to send over the UART configured for internal loopback.
    		//    //
    		//    ui8DataTx[0] = 'O';
    		//    ui8DataTx[1] = 'M';
    		//    ui8DataTx[2] = 'K';
    		//    ui8DataTx[3] = 'R';
    
    		//    //
    		//    // Inform user that data is being sent over for internal loopback.
    		//    //
    		//    UARTSend(UART0_BASE, (uint8_t*)"\n\n\rSending : ",strlen("\n\n\rSending : "));
    		//    UARTSend(UART0_BASE, (uint8_t*)ui8DataTx, NUM_UART_DATA);
    		//		
    		//*****************************************************************************
    		//
    		// To write the data into the buffer during runtime
    		//
    		//*****************************************************************************
    
    		for(uint8_t i=0 ; x!= '@' ; i++)
    		{
    			x = UARTCharGet(UART0_BASE);
    			ui8DataTx[i] = x ;
    			len++;
    		}
    
    		UARTSend(UART0_BASE, (uint8_t*)ui8DataTx, len-1);
    //*****************************************************************************	
        //
        // Send the data, which was prepared above, over the UART configured for
        // internal loopback operation.
        //
        for(ui32index = 0 ; ui32index < NUM_UART_DATA ; ui32index++)
        {
            UARTCharPut(UART7_BASE, ui8DataTx[ui32index]);
        }
    
        while(MAP_UARTBusy(UART7_BASE))
        {
        }
    
        UARTSend(UART0_BASE, (uint8_t *)"\n\rReceiving : ",strlen("\n\rReceiving : "));
    
        for(ui32index = 0 ; ui32index < NUM_UART_DATA ; ui32index++)
        {
            ui8DataRx[ui32index] = UARTCharGet(UART7_BASE);
        }
    
        UARTSend(UART0_BASE, (uint8_t*)ui8DataRx, NUM_UART_DATA);		
    
    	}
    	
    	else if(y == 'd' || y == 'D')
    	{
    	 UARTSend(UART0_BASE, (uint8_t *)"\n**************Default Settings**************",strlen("\n************Default Settings************"));	
    	 UARTSend(UART0_BASE, (uint8_t *)"\nBaud Rate = 115200",strlen("\nBaud Rate = 115200"));	
       UARTSend(UART0_BASE, (uint8_t *)"\nData Size = 8 bits",strlen("\nData Size = 8 bits"));		
       UARTSend(UART0_BASE, (uint8_t *)"\nMode      = Free",strlen("\nMode      = Free"));
    	 UARTSend(UART0_BASE, (uint8_t *)"\nParity    = None\n",strlen("\nParity    = None\n"));
    	}
    	UARTSend(UART0_BASE, (uint8_t *)"\nNow go to the new baud rate terminal",strlen("\nNow go to the new baud rate terminal"));
    }
     }


    it's getting stuck at the choose suitable bit.

    Regards

    Omkar Dixit

  • I don't see any code where you convert from ascii to integer.

  • Hi Charles

    Actually I have assigned numbers serially to the standard baud rates. User have choise to choose between 1 to 7. So according to the no entered by the user it will go into the switch and here the baud rate will get assigned to the member of the structure which i declared above the main. At the end of the if else i'm changing the uart parameters.

    SysCtlPeripheralReset(SYSCTL_PERIPH_UART0);
    														
    MAP_UARTConfigSetExpClk(UART0_BASE, ui32SysClock, setting.baud_rate,(setting.Bits |setting.Stop_Bits |setting.parity));

    Regards,
    Omkar Dixit

  • Hi,

      Are you saying after you call the MAP_UARTConfigSetExpClk, the baud rate was not changed?

      First of the all, is below line really called? If it is called, can you single step and also watch the register window for UART0 to see if the baud rate is changed or not. Make sure the setting.baud_rate indeed contains the new baud rate value. 

    MAP_UARTConfigSetExpClk(UART0_BASE, ui32SysClock, setting.baud_rate,(setting.Bits |setting.Stop_Bits |setting.parity));

  • Hi

    Thank you so much for giving me a direction. I will definitely try and will update.

    Regards,

    Omkar Dixit 

  • Hi Charles

    I checked the UART0_BASE, ui32SysClock, setting.baud_rate,(setting.Bits |setting.Stop_Bits |setting.parity) and there values are not getting changed so i add ASCII values to the switch condition and after this change values are changed. 

    But now sir when the UART settings are changed the very next step is to again change the baud rate on the terminal and then see the menu. But, this process is too fast and thats why after changing baud rate on the terminal data is not there but i tried the same thing by adding breakpoint. So by adding breakpoint i can easily change the terminal baud rate and by running again i can able to see the menu again on the different baud rate. But without debugging its not possible.

    That means if i simply flash code and then if i try then the menu is not printing after the setting are changed. But menu is printed even after changing the baud rate if i debug by using breakpoint. 

    So i think i need to add somewhere delay so that after settings changed user will change the baud rate so for this process user will take at least some sec so i think i  need to add some sec delay so that automatically execution will stop for that period and after user changed baud rate there will be menu shown.

    Here is the changed code,

    Regards

    Omkar Dixit

    #include <stdint.h>
    #include <stdbool.h>
    #include <stdio.h>
    
    #include "TM4C129.h"                    // Device header
    #include "RTE_Components.h"             // Component selection
    
    #include "FreeRTOSConfig.h"             // ARM.FreeRTOS::RTOS:Config
    #include "FreeRTOS.h"                   // ARM.FreeRTOS::RTOS:Core
    #include "task.h"                       // ARM.FreeRTOS::RTOS:Core
    #include "timers.h"                     // ARM.FreeRTOS::RTOS:Timers
    #include "EventRecorder.h"              // Keil.ARM Compiler::Compiler:Event Recorder
    #include "EventRecorderConf.h"          // Keil.ARM Compiler::Compiler:Event Recorder
    
    
    //*****************************************************************************
    #include "inc/hw_types.h"
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_nvic.h"
    #include "driverlib/debug.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    
    /********Macros Used*********/
    #define NUM_UART_DATA           100
    //#define NUM_UART_DATA         4
    #define SYSCTL_SRUART_R0        0x00000001  // UART Module 0 Software Reset
    #define UART_O_PP               0x00000FC0  // UART Peripheral Properties
    #define UART_O_FR               0x00000018  // UART Flag
    
    
    //*****************************************************************************
    //!
    //! This example shows how to set up the UART and use polled I/O methods
    //! for transmitting and receiving UART data.  The example receives characters
    //! from UART0 and retransmits the same character using UART0.  It can be
    //! tested by using a serial terminal program on a host computer.  This
    //! example will echo every character that is type until the return/enter key
    //! is pressed.
    //!
    //! This example uses the following peripherals and I/O signals.  You must
    //! review these and change as needed for your own board:
    //! - UART0 peripheral
    //! - GPIO Port A peripheral (for UART0 pins)
    //! - UART0RX - PA0
    //! - UART0TX - PA1
    //
    //*****************************************************************************
    
    /* Function Prototypes */
    static void prvSetupHardware( void );
    void Task1( void *pvParameters );
    void Task2( void *pvParameters );
    
    static void Serial_Port_Settings( void );
    static void Exit( void );	
    static void Read_Data( void );	
    static void Default_Settings( void );
    extern void UARTSend(uint32_t ui32UARTBase, const uint8_t *pui8Buffer, uint32_t ui32Count);
    extern void SysCtlReset(void);
    
    /* Variable */
    uint32_t ui32SysClock;
    BaseType_t ret;
    char x,y=0,z;
    uint32_t len;
    uint8_t ui8DataTx[NUM_UART_DATA];
    uint8_t ui8DataRx[NUM_UART_DATA];
    uint32_t ui32index;
    uint8_t i;
    uint8_t RESET=1;
    
    /*Structures Used*/
    struct settings{
    	int baud_rate;
    	uint32_t Bits,Stop_Bits;
    	char parity;
    }setting;
    
    
    /************************Functions Definations************************/
    static void prvSetupHardware( void )
    {	
    		if(RESET == 1 )
    		{
    			
    	  ui32SysClock = SystemCoreClock;
        //
        // Enable the peripherals used by this example.
        // The UART itself needs to be enabled, as well as the GPIO port
        // containing the pins that will be used.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        //
        // Configure the GPIO pin muxing for the UART function.
        // This is only necessary if your part supports GPIO pin function muxing.
        // Study the data sheet to see which functions are allocated per pin.
        // TODO: change this to select the port/pin you are using
        //
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);	
        //
        // Since GPIO A0 and A1 are used for the UART function, they must be
        // configured for use as a peripheral function (instead of GPIO).
        // TODO: change this to match the port/pin you are using
        //
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Configure the UART for 115,200, 8-N-1 operation.
        // This function uses SysCtlClockGet() or ui32SysClock to get the system clock
        // frequency.  This could be also be a variable or hard coded value
        // instead of a function call.
        //
        UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 9600,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));
    		}
    		else if(RESET >=2 )
    		{
    			
    	  ui32SysClock = SystemCoreClock;
        //
        // Enable the peripherals used by this example.
        // The UART itself needs to be enabled, as well as the GPIO port
        // containing the pins that will be used.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        //
        // Configure the GPIO pin muxing for the UART function.
        // This is only necessary if your part supports GPIO pin function muxing.
        // Study the data sheet to see which functions are allocated per pin.
        // TODO: change this to select the port/pin you are using
        //
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);	
        //
        // Since GPIO A0 and A1 are used for the UART function, they must be
        // configured for use as a peripheral function (instead of GPIO).
        // TODO: change this to match the port/pin you are using
        //
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Configure the UART for 115,200, 8-N-1 operation.
        // This function uses SysCtlClockGet() or ui32SysClock to get the system clock
        // frequency.  This could be also be a variable or hard coded value
        // instead of a function call.
        //
        UARTConfigSetExpClk(UART0_BASE, ui32SysClock, setting.baud_rate,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));													
    		}	
    		
    }
    												 
    
    static void Serial_Port_Settings( void )
    {
    		UARTSend(UART0_BASE, (uint8_t *)"\n**************Serial Port Settings**************",strlen("\n**************Serial Port Settings**************"));	
    													 UARTSend(UART0_BASE, (uint8_t *)"\nEnter the (Baud Rate)-(No of bits)-(Parity)-(Stop Bits) one by one",strlen("\nEnter the (Baud Rate)-(No of bits)-(Parity)-(Stop Bits) one by one"));	
    													 
    													 UARTSend(UART0_BASE, (uint8_t *)"\nChoose suitable baud rate from the above list:",strlen("\nChoose suitable baud rate from the above list:"));
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(1):9600",strlen("\n(1):9600"));		
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(2):14400",strlen("\n(2):14400"));	
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(3):19200",strlen("\n(3):19200"));	
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(4):38400",strlen("\n(4):38400"));	
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(5):56000",strlen("\n(5):56000"));	
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(6):57600",strlen("\n(6):57600"));	
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(7):115200",strlen("\n(7):115200"));			
    															
    														z = UARTCharGet(UART0_BASE);
    		
    													if(z==0x31||z==0x32||z==0x33||z==0x34||z==0x35||z==0x36||z==0x37)
    													{
    														UARTSend(UART0_BASE, (uint8_t *)"\nOk...\n\n\n",strlen("\nOk...\n\n\n"));
    																		switch(z)
    																		{
    																			case 0x31: setting.baud_rate = 9600;
    																		break;
    																			case 0x32 : setting.baud_rate = 14400;
    																		break;
    																			case 0x33: setting.baud_rate = 19200;
    																		break;
    																			case 0x34: setting.baud_rate = 38400;
    																		break;
    																			case 0x35: setting.baud_rate = 56000;
    																		break;
    																			case 0x36: setting.baud_rate = 57600;
    																		break;	
    																			case 0x37: setting.baud_rate = 115200;
    																		break;			
    																		}
    													}
    														else
    														{
    																	UARTSend(UART0_BASE, (uint8_t *)"\nPlease try again...\n\n",strlen("\nPlease try again...\n\n"));
    															Serial_Port_Settings();
    														}	
    															
    													 UARTSend(UART0_BASE, (uint8_t *)"\nChoose suitable Data Bits from the above list:",strlen("\nChoose suitable Data Bits from the above list:"));
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(1):7-Bit",strlen("\n(1):7-Bit"));		
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(2):8-Bit",strlen("\n(2):8-Bit"));
    														
    															z = UARTCharGet(UART0_BASE);		
    														
    														if(z == 0x31 || z == 0x32)
    														{
    														UARTSend(UART0_BASE, (uint8_t *)"\nOk...\n\n\n",strlen("\nOk...\n\n\n"));
    																	switch(z)
    																	{
    																		case 0x31: setting.Bits = UART_CONFIG_WLEN_7;
    																	break;
    																		case 0x32 : setting.Bits = UART_CONFIG_WLEN_8;
    																	break;
    																	}
    														}
    														else
    														{
    															UARTSend(UART0_BASE, (uint8_t *)"\nPlease try again...\n\n",strlen("\nPlease try again...\n\n"));
    															Serial_Port_Settings();
    														}
    														
    													 UARTSend(UART0_BASE, (uint8_t *)"\nChoose suitable Parity option from the above list:",strlen("\nChoose suitable Parity option from the above list:"));
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(1):None",strlen("\n(1):None"));		
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(2):Even",strlen("\n(2):Even"));
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(3):Odd",strlen("\n(2):Odd"));	
    												       
    													 z = UARTCharGet(UART0_BASE);		
    														
    														if(z == 0x31 || z == 0x32 || z == 0x33)
    														{
    														UARTSend(UART0_BASE, (uint8_t *)"\nOk...\n\n\n",strlen("\nOk...\n\n\n"));
    																switch(z)
    																{
    																	case 0x31: setting.parity = UART_CONFIG_PAR_NONE;
    																break;
    																	case 0x32 : setting.parity = UART_CONFIG_PAR_EVEN;
    																break;
    																	case 0x33 : setting.parity = UART_CONFIG_PAR_ODD;
    																break;
    																}			
    													}
    														else
    														{
    																	UARTSend(UART0_BASE, (uint8_t *)"\nPlease try again...\n\n",strlen("\nPlease try again...\n\n"));
    															    Serial_Port_Settings();
    														}
    
    													 UARTSend(UART0_BASE, (uint8_t *)"\nChoose suitable No of stop Bits from the above list:",strlen("\nChoose suitable No of stop Bits from the above list:"));
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(1):1 Stop Bit",strlen("\n(1):1 Stop Bit"));		
    													 UARTSend(UART0_BASE, (uint8_t *)"\n(2):2 Stop Bit\n\n",strlen("\n(2):2 Stop Bit\n\n"));
    														
    														z = UARTCharGet(UART0_BASE);		
    														if(z == 0x31 ||z == 0x32)
    														{
    																	switch(z)
    																	{
    																		case 0x31: setting.Stop_Bits = UART_CONFIG_STOP_ONE;
    																	break;
    																		case 0x32 : setting.Stop_Bits = UART_CONFIG_STOP_TWO;
    																	break;			
    																	}
    													}
    														else
    															{
    																UARTSend(UART0_BASE, (uint8_t *)"\nPlease try again...\n\n",strlen("\nPlease try again...\n\n"));		
    																Serial_Port_Settings();														
    															}
    																									
    													UARTSend(UART0_BASE, (uint8_t *)"\nsettings saved....\n\n",strlen("\nsettings saved....\n\n"));
    													RESET++;
    													prvSetupHardware();
    													void Task1( void *pvParameters );
    													void Task2( void *pvParameters );
    															
    														}
    static void Exit( void )	
    {
    	 UARTSend(UART0_BASE, (uint8_t *)"\n**************Exit**************",strlen("\n**************Exit**************"));
    }
    	
    static void Read_Data( void )	
    {
       UARTSend(UART0_BASE, (uint8_t *)"\n**************Read Data**************",strlen("\n**************Read Data**************"));					
    	 UARTSend(UART0_BASE, (uint8_t *)"\n(Press '@' on the keyboard when you done writing on the terminal)",strlen("\n(Press '@' on the keyboard when you done writing on the terminal)"));	
    	 UARTSend(UART0_BASE, (uint8_t *)"\nNow Enter The Characters :",strlen("\nNow Enter The Characters :"));
    
    		//*****************************************************************************
    		//
    		// to write data during programming 
    		//
    		//*****************************************************************************
    			
    //		    //
    //		    // Prepare data to send over the UART configured for internal loopback.
    //		    //
    //		    ui8DataTx[0] = 'O';
    //		    ui8DataTx[1] = 'M';
    //		    ui8DataTx[2] = 'K';
    //		    ui8DataTx[3] = 'R';
    
    //		    //
    //		    // Inform user that data is being sent over for internal loopback.
    //		    //
    //		    UARTSend(UART0_BASE, (uint8_t*)"\n\n\rSending : ",strlen("\n\n\rSending : "));
    //		    UARTSend(UART0_BASE, (uint8_t*)ui8DataTx, NUM_UART_DATA);
    				
    		//*****************************************************************************
    		//
    		// To write the data into the buffer during runtime
    		//
    		//*****************************************************************************
    
    		for(i=0 ; x!= '@' ; i++)
    		{
    			x = UARTCharGet(UART0_BASE);
    			ui8DataTx[i] = x ;
    			len++;
    		}
    
    		UARTSend(UART0_BASE, (uint8_t*)ui8DataTx, len-1);
    		UARTSend(UART0_BASE, (uint8_t*)"\nDone...\n\n", strlen("\nDone\n\n"));
    
    }
    	
    static void Default_Settings( void )	
    {
    	 UARTSend(UART0_BASE, (uint8_t *)"\n**************Default Settings**************",strlen("\n************Default Settings************"));	
    	 UARTSend(UART0_BASE, (uint8_t *)"\nBaud Rate = 115200",strlen("\nBaud Rate = 115200"));	
       UARTSend(UART0_BASE, (uint8_t *)"\nData Size = 8 bits",strlen("\nData Size = 8 bits"));		
       UARTSend(UART0_BASE, (uint8_t *)"\nMode      = Free",strlen("\nMode      = Free"));
    	 UARTSend(UART0_BASE, (uint8_t *)"\nParity    = None\n",strlen("\nParity    = None\n"));	
    }
    
    
    
    int main()
    {
    			/* Configure the clocks, UART and GPIO */
    			prvSetupHardware();	
    	
          /* TASK creation */
          ret = xTaskCreate(Task1,"Transmit_Receive",240,NULL,tskIDLE_PRIORITY + 1UL,NULL );
          configASSERT(ret);
    	    ret = xTaskCreate(Task2,"Take_input_from_user",240,NULL,tskIDLE_PRIORITY + 1UL,NULL );
          configASSERT(ret);
    
    
          vTaskStartScheduler();
    
        //
        // Idle Task
        //
        while(1)
        {
        }
    }
    
    void Task1( void *pvParameters ) /*This task is used to just show menu on the terminal*/
    {
    	UARTSend(UART0_BASE, (uint8_t *)"\n************$$Tapa ullekhaka$$************",strlen("\n************$$Tapa ullekhaka$$************"));
    	UARTSend(UART0_BASE, (uint8_t *)"\nHardware                 : EK-TM4C1294XL",strlen("\nHardware                 : EK-TM4C1294XL"));	
    	UARTSend(UART0_BASE, (uint8_t *)"\nSoftware Version         : 1.0\n",strlen("\nSoftware Version         : 1.0\n"));
    	UARTSend(UART0_BASE, (uint8_t *)"*****************************************\n",strlen("*****************************************\n"));
    	UARTSend(UART0_BASE, (uint8_t *)"\nSelect one of the options from the below",strlen("\nSelect one of the options from the below"));	
    
    	UARTSend(UART0_BASE, (uint8_t *)"\nSerial Port Settings-> s",strlen("\nSerial Port Settings-> s"));
    	UARTSend(UART0_BASE, (uint8_t *)"\nExit                -> e",strlen("\nExit                -> e"));	
    	UARTSend(UART0_BASE, (uint8_t *)"\nRead Data           -> r",strlen("\nRead Data           -> r"));
    	UARTSend(UART0_BASE, (uint8_t *)"\nDefault             -> d",strlen("\nDefault             -> d"));
    	
    }
    
    void Task2( void *pvParameters ) /*This task is used to Take the input from user and act accordingly*/
    {
    		while(1)
    	{
    		y = UARTCharGet(UART0_BASE);
    			
    			if(y == 's' || y == 'S')  /*Check whether "Serial Port Settings" selected*/
    			   {Serial_Port_Settings();}		
    			
    					else if(y == 'e' || y == 'E')/*Check whether "Exit" selected*/
    					        {Exit();}
    		
    						else if(y == 'r' || y =='R')/*Check whether "Read Data" selected*/
    						        {Read_Data();}
    		
    							else if(y == 'd' || y == 'D')/*Check whether "Default" selected*/
    							        {Default_Settings();}
    	}
    }	
    

  • Hi,

      I'm not too clear about your application. Why would you want to change the baudrate on the fly?  How will you know how long to wait before changing the baud rate on the UART? What if the user on the terminal side waited a hour to change the baud rate setting? I think you need to add some handshake between MCU and the terminal. Perhaps the terminal needs to send a timer command so the MCU knows exactly how long to wait. For example:

      1. The terminal sends the new baud rate.

       2. The MCU only saves the new setting on a buffer. It does not not change the UART setting unless it receives a timer command from the terminal.

       3. The terminal sends a timer command with a 1 minute timeout value. This is only an example. It is up to the terminal on what this timer is.

       4. After the MCU receives the timer value, it will wait after 1 minute before actually changing the UART value.

       5. During this minute period, the user on the terminal side has time to change the terminal baud rate. 

       6. The MCU sends a OK message to the terminal expecting the user to acknowledge.

       7. If the terminal does not acknowledge within certain time frame, the MCU will revert back to it prior baud rate setting.

    You will need to come up with your own protocol on the best way to handle the synchronization. The above steps may not work if the user waited longer than a 1 minute. I really don't see a good way to handle this. The baud rate should be static and established in the very beginning and agreed upon by everyone. I still don't understand why offer changing the baud rate on the fly.

  • Hi 

    Thank you so much for your detailed message it really helped me. Actually i asked my senior who actually assigned this task to me he simply said client may require in future i'm not sure whether he is clear on this task or not. But, I agree with you that the baud rate should be static.

    Thank You

    Omkar