TM4C123GH6PM | UART | UART Serial communication | UART interfacing with TM4C Launch Pad | UART Program
- Get link
- X
- Other Apps
UART interfacing with TM4C Launch Pad
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);// 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);
// CONFIGURE UART, BAUD RATE 115200, DATA BITS 8, STOP BIT 1, PARITY NONE
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
UARTCharPut(UART0_BASE, 'E');
UARTCharPut(UART0_BASE, 'c');
UARTCharPut(UART0_BASE, 'h');
UARTCharPut(UART0_BASE, 'o'); // SEND "Echo Output: " IN UART
UARTCharPut(UART0_BASE, ' ');
UARTCharPut(UART0_BASE, 'O');
UARTCharPut(UART0_BASE, 'u');
UARTCharPut(UART0_BASE, 't');
UARTCharPut(UART0_BASE, 'p');
UARTCharPut(UART0_BASE, 'u');
UARTCharPut(UART0_BASE, 't');
UARTCharPut(UART0_BASE, ': ');
UARTCharPut(UART0_BASE, ' ');
UARTCharPut(UART0_BASE, '\n');
while (1)
{
//UART ECHO - what is received is transmitted back //
if (UARTCharsAvail(UART0_BASE))
UARTCharPut(UART0_BASE,UARTCharGet(UART0_BASE));
}
}
#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);// 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);
// CONFIGURE UART, BAUD RATE 115200, DATA BITS 8, STOP BIT 1, PARITY NONE
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
UARTCharPut(UART0_BASE, 'E');
UARTCharPut(UART0_BASE, 'c');
UARTCharPut(UART0_BASE, 'h');
UARTCharPut(UART0_BASE, 'o'); // SEND "Echo Output: " IN UART
UARTCharPut(UART0_BASE, ' ');
UARTCharPut(UART0_BASE, 'O');
UARTCharPut(UART0_BASE, 'u');
UARTCharPut(UART0_BASE, 't');
UARTCharPut(UART0_BASE, 'p');
UARTCharPut(UART0_BASE, 'u');
UARTCharPut(UART0_BASE, 't');
UARTCharPut(UART0_BASE, ': ');
UARTCharPut(UART0_BASE, ' ');
UARTCharPut(UART0_BASE, '\n');
while (1)
{
//UART ECHO - what is received is transmitted back //
if (UARTCharsAvail(UART0_BASE))
UARTCharPut(UART0_BASE,UARTCharGet(UART0_BASE));
}
}
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 (115200)àok button.
17. Open cc studio and click on Resume button.
TM4C123GH6PM Overall Documentation in video description
Video 👇
Comments
Post a Comment