TM4C123GH6PM | UART | UART Serial communication | UART interfacing with push button | Switch Pressed

UART interfacing with push button

Program

#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 GPIO_PA0_U0RX 0x00000001 // UART PIN ADDRESS FOR UART RX
#define GPIO_PA1_U0TX 0x00000401 // UART PIN ADDRESS FOR UART TX
int main(void)
{
// SYSTEM CLOCK AT 40 MHZ
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
// ENABLE PERIPHERAL UART 0
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);
// ENABLE GPIO PORT A,FOR UART
GPIOPinConfigure(GPIO_PA0_U0RX); // PA0 IS CONFIGURED TO UART RX
GPIOPinConfigure(GPIO_PA1_U0TX); // PA1 IS CONFIGURED TO UART TX
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD_WPU);
// CONFIGURE UART, BAUD RATE 115200, DATA BITS 8, STOP BIT 1, PARITY NONE
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 19200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

while (1)
{
    while(!GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4))
            {
    UARTCharPut(UART0_BASE,'s');
    UARTCharPut(UART0_BASE,'w');
    UARTCharPut(UART0_BASE,'i');
    UARTCharPut(UART0_BASE,'t');
    UARTCharPut(UART0_BASE,'c');
    UARTCharPut(UART0_BASE,'h');
    UARTCharPut(UART0_BASE,' ');
    UARTCharPut(UART0_BASE,'p');
    UARTCharPut(UART0_BASE,'r');
    UARTCharPut(UART0_BASE,'e');
    UARTCharPut(UART0_BASE,'s');
    UARTCharPut(UART0_BASE,'s');
    UARTCharPut(UART0_BASE,'e');
    UARTCharPut(UART0_BASE,'d');
    UARTCharPut(UART0_BASE,'\n');
    while(!GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4));

        }
}
}

Procedure

1. Create a new folder on desktop location.

2. Open cc studio on desktop.

3. Browse the workspace location

    Click on browseàdesktopàselect created folderàok button.

4. ccs wizard is opened

     Click on projectànew ccs projectàtarget [select Tiva c series].

5. Select microcontroller “Tiva TM4C123GH6PM”, click on connection and select “Stellaris in-circuit debug interface”.        

6. Name the project in project name bar and click on finish button.

7. Click on restore button on left side and then enter the programà save button.

8. Now unfold the project and right click on project and select properties.

9. Select include optionsàaddàbrowseàmy computeràlocal disc càtià
    Tivaware_c_series_2.1.2.111
àok. Now directory path is added to project then click on ok
    button.

10. Select projectà Right click on project à add files à select local disc cà  select tià Tivaware_c_series_2.1.2.111 àselect driverlib à ccs à debug à driverlib.lib à open button.

11. Select copy files and click ok button. Now driver library file is added to the project.                                                                                                                           

12. To build the project click on Build button.


13. After building the project is finished. Connect TM4C launch pad to pc using USB cable.

14. Before debugging set the launch pad in debug mode by pushing wake up pin and click on debug            button in ccstudio and minimize ccs after completing debugging.

15. Select TeraTerm icon on desktop
àselect serialàselect port [C0M7: Stellaris Virtual serial          port]àok button.

16. Select setup in [COM7-TeraTerm]
àserial portàselect baudrate (19200)àok button.

17.  Open cc studio and click on Resume button.


TM4C123GH6PM Overall Documentation in video description

Video 👇








Comments