Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

UART2 Not Working

$
0
0

Hi, 

Am using LM4F232H5QD Evalution Board. I am currently trying to program the uart_echo example code. this code working fine for the UART0. but the same code when used for the UART2 its not working.  its giving garbage values. am posting my code. I am hoping to get help with a problem that I have been facing.

*****************
#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/rom.h"
#include "grlib/grlib.h"
#include "drivers/cfal96x64x16.h"

void
UARTSend(const unsigned char *pucBuffer, unsigned long ulCount);
unsigned char ucCharu;

//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>UART Echo (uart_echo)</h1>
//!
//! This example application utilizes the UART to echo text. The first UART
//! (connected to the USB debug virtual serial port on the evaluation board)
//! will be configured in 115,200 baud, 8-n-1 mode. All characters received on
//! the UART are transmitted back to the UART.
//
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif

void delay(unsigned long loop)
{
unsigned long l,h;
for(l=0;l<=loop;l++)
for(h=0;h<10000;h++);
}
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void
UARTIntHandler(void)
{
unsigned long ulStatus;

//
// Get the interrrupt status.
//
ulStatus = ROM_UARTIntStatus(UART2_BASE, true);
/*if(ulStatus == '>')
{
UARTSend((const unsigned char *)" : Command Mode:\n", 17);
delay(6);
UARTSend((const unsigned char *)"Please Enter \'X\' to Exit: ", 28);
delay(6);
} */
//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART2_BASE, ulStatus);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail((UART2_BASE)))
{
//
// Read the next character from the UART and write it back to the UART.
//
ucCharu= ROM_UARTCharPutNonBlocking(UART2_BASE,
ROM_UARTCharGetNonBlocking(UART2_BASE));

/* ucCharu = ROM_UARTCharGetNonBlocking(UART2_BASE);
ROM_UARTCharPutNonBlocking(UART2_BASE, ucCharu);*/

if(ucCharu == 's')
{
UARTSend((const unsigned char *)" : Command Mode:\n", 17);
delay(6);

// GPIODirModeSet(GPIO_PORTB_BASE,GPIO_PIN_2,GPIO_DIR_MODE_OUT);
// GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_2);
// GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_2,0x00000001);

//if(GPIO_PIN_2==0x)
UARTSend((const unsigned char *)"data mode:\n ", 28);
delay(6);
}
}
}

//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
void
UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
//
// Loop while there are more characters to send.
//
while(ulCount--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART2_BASE, *pucBuffer++);
}
}

//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
tRectangle sRect;
tContext sContext;

//
// The FPU should be enabled because some compilers will use floating-
// point registers, even for non-floating-point code. If the FPU is not
// enabled this will cause a fault. This also ensures that floating-
// point operations could be added to this application and would work
// correctly and use the hardware floating-point unit. Finally, lazy
// stacking is enabled for interrupt handlers. This allows floating-
// point instructions to be used within interrupt handlers, but at the
// expense of extra stack usage.
//
FPUEnable();
FPULazyStackingEnable();

//
// Set the clocking to run directly from the crystal.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);

//
// Initialize the display driver.
//
//CFAL96x64x16Init();

//
// Initialize the graphics context.
//
//GrContextInit(&sContext, &g_sCFAL96x64x16);

//
// Fill the top part of the screen with blue to create the banner.
//
/* sRect.sXMin = 0;
sRect.sYMin = 0;
sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1;
sRect.sYMax = 9;
GrContextForegroundSet(&sContext, ClrDarkBlue);
GrRectFill(&sContext, &sRect);

//
// Change foreground for white text.
//
//GrContextForegroundSet(&sContext, ClrWhite);

//
// Put the application name in the middle of the banner.
//
/* GrContextFontSet(&sContext, g_pFontFixed6x8);
GrStringDrawCentered(&sContext, "uart-echo", -1,
GrContextDpyWidthGet(&sContext) / 2, 4, 0);

//
// Initialize the display and write some instructions.
//
/* GrStringDrawCentered(&sContext, "Connect a", -1,
GrContextDpyWidthGet(&sContext) / 2, 20, false);
GrStringDrawCentered(&sContext, "terminal", -1,
GrContextDpyWidthGet(&sContext) / 2, 30, false);
GrStringDrawCentered(&sContext, "to UART0.", -1,
GrContextDpyWidthGet(&sContext) / 2, 40, false);
GrStringDrawCentered(&sContext, "115000,N,8,1", -1,
GrContextDpyWidthGet(&sContext) / 2, 50, false); */

//
// Enable the peripherals used by this example.
//
//ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
//ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);

//
// Enable processor interrupts.
//
ROM_IntMasterEnable();

//
// Set GPIO A0 and A1 as UART pins.
//
ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_7 | GPIO_PIN_6);
// ROM_GPIOPinTypeUART(GPIO_PORTG_BASE, GPIO_PIN_4 | GPIO_PIN_5);
//
// Configure the UART for 115,200, 8-N-1 operation.
//
ROM_UARTConfigSetExpClk(UART2_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//
// Enable the UART interrupt.
//
ROM_IntEnable(INT_UART2);
ROM_UARTIntEnable(UART2_BASE, UART_INT_RX | UART_INT_RT);

//
// Prompt for text to be entered.
//
UARTSend((unsigned char *)"chethan kumar :::", 18);

//
// Loop forever echoing data through the UART.
//
while(1)
{
}
}

*****************
#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/rom.h"
#include "grlib/grlib.h"
#include "drivers/cfal96x64x16.h"

void
UARTSend(const unsigned char *pucBuffer, unsigned long ulCount);
unsigned char ucCharu;

//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>UART Echo (uart_echo)</h1>
//!
//! This example application utilizes the UART to echo text. The first UART
//! (connected to the USB debug virtual serial port on the evaluation board)
//! will be configured in 115,200 baud, 8-n-1 mode. All characters received on
//! the UART are transmitted back to the UART.
//
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif

void delay(unsigned long loop)
{
unsigned long l,h;
for(l=0;l<=loop;l++)
for(h=0;h<10000;h++);
}
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void
UARTIntHandler(void)
{
unsigned long ulStatus;

//
// Get the interrrupt status.
//
ulStatus = ROM_UARTIntStatus(UART2_BASE, true);
/*if(ulStatus == '>')
{
UARTSend((const unsigned char *)" : Command Mode:\n", 17);
delay(6);
UARTSend((const unsigned char *)"Please Enter \'X\' to Exit: ", 28);
delay(6);
} */
//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART2_BASE, ulStatus);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail((UART2_BASE)))
{
//
// Read the next character from the UART and write it back to the UART.
//
ucCharu= ROM_UARTCharPutNonBlocking(UART2_BASE,
ROM_UARTCharGetNonBlocking(UART2_BASE));

/* ucCharu = ROM_UARTCharGetNonBlocking(UART2_BASE);
ROM_UARTCharPutNonBlocking(UART2_BASE, ucCharu);*/

if(ucCharu == 's')
{
UARTSend((const unsigned char *)" : Command Mode:\n", 17);
delay(6);

// GPIODirModeSet(GPIO_PORTB_BASE,GPIO_PIN_2,GPIO_DIR_MODE_OUT);
// GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_2);
// GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_2,0x00000001);

//if(GPIO_PIN_2==0x)
UARTSend((const unsigned char *)"data mode:\n ", 28);
delay(6);
}
}
}

//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
void
UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
//
// Loop while there are more characters to send.
//
while(ulCount--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART2_BASE, *pucBuffer++);
}
}

//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
tRectangle sRect;
tContext sContext;

//
// The FPU should be enabled because some compilers will use floating-
// point registers, even for non-floating-point code. If the FPU is not
// enabled this will cause a fault. This also ensures that floating-
// point operations could be added to this application and would work
// correctly and use the hardware floating-point unit. Finally, lazy
// stacking is enabled for interrupt handlers. This allows floating-
// point instructions to be used within interrupt handlers, but at the
// expense of extra stack usage.
//
FPUEnable();
FPULazyStackingEnable();

//
// Set the clocking to run directly from the crystal.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);

//
// Initialize the display driver.
//
//CFAL96x64x16Init();

//
// Initialize the graphics context.
//
//GrContextInit(&sContext, &g_sCFAL96x64x16);

//
// Fill the top part of the screen with blue to create the banner.
//
/* sRect.sXMin = 0;
sRect.sYMin = 0;
sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1;
sRect.sYMax = 9;
GrContextForegroundSet(&sContext, ClrDarkBlue);
GrRectFill(&sContext, &sRect);

//
// Change foreground for white text.
//
//GrContextForegroundSet(&sContext, ClrWhite);

//
// Put the application name in the middle of the banner.
//
/* GrContextFontSet(&sContext, g_pFontFixed6x8);
GrStringDrawCentered(&sContext, "uart-echo", -1,
GrContextDpyWidthGet(&sContext) / 2, 4, 0);

//
// Initialize the display and write some instructions.
//
/* GrStringDrawCentered(&sContext, "Connect a", -1,
GrContextDpyWidthGet(&sContext) / 2, 20, false);
GrStringDrawCentered(&sContext, "terminal", -1,
GrContextDpyWidthGet(&sContext) / 2, 30, false);
GrStringDrawCentered(&sContext, "to UART0.", -1,
GrContextDpyWidthGet(&sContext) / 2, 40, false);
GrStringDrawCentered(&sContext, "115000,N,8,1", -1,
GrContextDpyWidthGet(&sContext) / 2, 50, false); */

//
// Enable the peripherals used by this example.
//
//ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
//ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);

//
// Enable processor interrupts.
//
ROM_IntMasterEnable();

//
// Set GPIO A0 and A1 as UART pins.
//
ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_7 | GPIO_PIN_6);
// ROM_GPIOPinTypeUART(GPIO_PORTG_BASE, GPIO_PIN_4 | GPIO_PIN_5);
//
// Configure the UART for 115,200, 8-N-1 operation.
//
ROM_UARTConfigSetExpClk(UART2_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//
// Enable the UART interrupt.
//
ROM_IntEnable(INT_UART2);
ROM_UARTIntEnable(UART2_BASE, UART_INT_RX | UART_INT_RT);

//
// Prompt for text to be entered.
//
UARTSend((unsigned char *)"chethan kumar :::", 18);

//
// Loop forever echoing data through the UART.
//
while(1)
{
}
}

 


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>