hello i am using tm4c123gh6pm ide is keil so what i am doing is sending data t uart1 and receive data send by GSM.
can any one suggest to make this code better.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.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/uart.h"
//#include <tm4c123gh6pm.h>
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
// The UART interrupt handler.
void UARTIntHandler(void)
{
uint32_t ui32Status;
// Get the interrrupt status.
ui32Status = ROM_UARTIntStatus(UART1_BASE, true);
// Clear the asserted interrupts.
ROM_UARTIntClear(UART1_BASE, ui32Status);
// Loop while there are characters in the receive FIFO.
while(ROM_UARTCharsAvail(UART1_BASE))
{
// Read the next character from the UART and write it back to the UART.
ROM_UARTCharPutNonBlocking(UART1_BASE, ROM_UARTCharGetNonBlocking(UART1_BASE));
// Blink the LED to show a character transfer is occuring.
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3);
// Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks.
SysCtlDelay(SysCtlClockGet() / (1000 * 3));
// Turn off the LED
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0);
}
}
// Send a string to the UART.
void UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART1_BASE, *pui8Buffer++);
}
}
void ConfigureUart(void){
uint8_t rxchar;
// Enable UART1
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
SysCtlDelay(5);
// Enable the GPIO Peripheral used by the UART.
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlDelay(5);
// Enable processor interrupts.
ROM_IntMasterEnable();
// Set GPIO B0 and B1 as UART pins.
ROM_GPIOPinConfigure(GPIO_PB0_U1RX);
ROM_GPIOPinConfigure(GPIO_PB1_U1TX);
ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
// Configure the UART for 115,200, 8-N-1 operation.
ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
// Enable the UART interrupt.
ROM_IntEnable(INT_UART1);
ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);
// Prompt for text to be entered.
UARTSend((uint8_t *)"\033[2JEnter text: ", 16);
UARTCharPut(UART1_BASE,'A');
UARTCharPut(UART1_BASE,'T');
UARTCharPut(UART1_BASE,'+');
UARTCharPut(UART1_BASE,'G');
UARTCharPut(UART1_BASE,'S');
UARTCharPut(UART1_BASE,'N');
UARTCharPut(UART1_BASE,'\r');
UARTCharPut(UART1_BASE,'\n');
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
UARTCharPut(UART1_BASE,'A');
UARTCharPut(UART1_BASE,'T');
UARTCharPut(UART1_BASE,'V');
UARTCharPut(UART1_BASE,'0');
UARTCharPut(UART1_BASE,'\r');
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
rxchar = UARTCharGet(UART1_BASE);
UARTCharPut(UART1_BASE,rxchar);
UARTCharPut(UART1_BASE,'\n');
// Loop forever echoing data through the UART.
//
while(1){ }
}
/*unsigned char Rx_Char()
{
while()
{
}
}*/
int main(void)
{
// Enable lazy stacking for interrupt handlers.
ROM_FPUEnable();
ROM_FPULazyStackingEnable();
// Set the clocking to run directly from the crystal.
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
// Enable the GPIO port that is used for the on-board LED.
// ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);
ConfigureUart();
return 0;
}