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.

Receive through UART2 and Transmit trough UART7 and VICE versa

Hi 

i am trying to use two ports at a time uart2 and uart7. i wan recieve through uart2 and send that data through uart7 and vice versa. have tried with below code but its transmitting from both the pors but its not taking interrupts... help me out where am going wrong

//*****************************************************************************
//
// uart_echo.c - Example for reading data from and writing data to the UART in
// an interrupt driven fashion.
//
// Copyright (c) 2011 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 8028 of the EK-LM4F232 Firmware Package.
//
//*****************************************************************************
#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);
void
UARTSend1(const unsigned char *pucBuffer, unsigned long ulCount);
unsigned char ucCharu2,ucCharu7;

//*****************************************************************************
//
//! \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 FOR UART2.
//
//*****************************************************************************
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));

ucCharu2 = ROM_UARTCharGetNonBlocking(UART2_BASE);
ROM_UARTCharPutNonBlocking(UART7_BASE, ucCharu2);

if(ucCharu2 == 's')
{


UARTSend((const unsigned char *)" : Command Mode:\n", 17);
delay(1);


UARTSend((const unsigned char *)"data mode:\n ", 28);
delay(1);
}
}
}

/************************************************************
iNTERRUPT HANDLER FOR UART7
*************************************************************/
void
UARTIntHandler1(void)
{
unsigned long ulStatus;
/******************************************************************/
ulStatus = ROM_UARTIntStatus(UART7_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(UART7_BASE, ulStatus);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail((UART7_BASE)))
{




// Read the next character from the UART and write it back to the UART.
//
// ucCharu= ROM_UARTCharPutNonBlocking(UART2_BASE,
// ROM_UARTCharGetNonBlocking(UART2_BASE));

ucCharu7 = ROM_UARTCharGetNonBlocking(UART7_BASE);
ROM_UARTCharPutNonBlocking(UART2_BASE, ucCharu7);
/*****************************************************************/



if(ucCharu7 == 's')
{


UARTSend1((const unsigned char *)" : Command Mode:\n", 17);
delay(1);


UARTSend1((const unsigned char *)"data mode:\n ", 28);
delay(1);
}
}
}

//*****************************************************************************
//
// Send a string to the UART7.
//
//*****************************************************************************/
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(UART7_BASE, *pucBuffer++);
}
}


//*****************************************************************************
//
// Send a string to the UART2.
//
//*****************************************************************************/
void
UARTSend1(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_GPIOE);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7);

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



/***********************************************************************************/

// Unlock access to the commit register
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD;
//
// Set the commit register for PD7 to allow changing the function
//
HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0x80;

//
// Enable the alternate function for PD7 (U2TX)
//
HWREG(GPIO_PORTD_BASE + GPIO_O_AFSEL) |= 0x400;

//
// Turn on the digital enable for PD7
//
HWREG(GPIO_PORTD_BASE + GPIO_O_DEN) |= 0x80;

//
// Relock the commit register
//
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = 0;

/*****************************************************/
ROM_GPIOPinConfigure(GPIO_PD7_U2TX);
ROM_GPIOPinConfigure(GPIO_PD6_U2RX);
ROM_GPIOPinConfigure(GPIO_PE1_U7TX);
ROM_GPIOPinConfigure(GPIO_PE0_U7RX);
ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);
ROM_GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1);

// 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));

ROM_UARTConfigSetExpClk(UART7_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
//UARTFlowControlSet(UART2_BASE, UART_FLOWCONTROL_NONE);

//
// Enable the UART interrupt.
//
ROM_IntEnable(INT_UART2);
ROM_UARTIntEnable(UART2_BASE, UART_INT_RX | UART_INT_RT);
ROM_IntEnable(INT_UART7);
ROM_UARTIntEnable(UART7_BASE, UART_INT_RX | UART_INT_RT);
//
// Prompt for text to be entered.

UARTSend((unsigned char *)"chethan kumar :::", 18);
UARTSend1((unsigned char *)"chethan kumar_2 :::", 18);

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