Hi All,
I am playing around with my LM4F232H5QD demo board, and I loaded the uart_echo program from the StellarisWare examples. I stripped out the graphics stuff to simplify the code. This code works great as is, on UART0. I type in characters from my terminal, and they get echoed back.
I need to use UART1 for my application, so I changed all of the UART0 references to UART1, GPIOA to GPIOB, and PORTA to PORTB. The code compiled and loaded fine, but no-worky. Nothing gets echoed back when I type characters from my terminal.
I did change the reference to the interrupt handler in startup_ccs.c, to point to UART1 as well. I also did move my FT232 UART adapter from PORTA pins to PB0 and PB1 after making the code changes.
I don't get it. Any help or pointers would be very appreciated.
Thanks, here are the 2 versions of the code:
Here is the working code for UART0:
#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"
// The error routine that is called if the driver library encounters an error.
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
// The UART interrupt handler.
void
UARTIntHandler(void)
{
unsigned long ulStatus;
// Get the interrrupt status.
ulStatus = ROM_UARTIntStatus(UART0_BASE, true);
// Clear the asserted interrupts.
ROM_UARTIntClear(UART0_BASE, ulStatus);
// Loop while there are characters in the receive FIFO.
while(ROM_UARTCharsAvail(UART0_BASE))
{
// Read the next character from the UART and write it back to the UART.
ROM_UARTCharPutNonBlocking(UART0_BASE,
ROM_UARTCharGetNonBlocking(UART0_BASE));
}
}
// 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(UART0_BASE, *pucBuffer++);
}
}
int
main(void)
{
// Enable lazy stacking for interrupt handlers. This allows floating-point
// instructions to be used within interrupt handlers, but at the expense of
// extra stack usage.
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 peripherals used by this example.
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
// Enable processor interrupts.
ROM_IntMasterEnable();
// Set GPIO A0 and A1 as UART pins.
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
// Configure the UART for 115,200, 8-N-1 operation.
ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
// Enable the UART interrupt.
ROM_IntEnable(INT_UART0);
ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
UARTSend((unsigned char *)"Enter text: ", 12);
while(1)
{
}
}
-----------------------------------------------------------
And here is the non-working code for UART1:
#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"
// The error routine that is called if the driver library encounters an error.
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
// The UART interrupt handler.
void
UARTIntHandler(void)
{
unsigned long ulStatus;
// Get the interrrupt status.
ulStatus = ROM_UARTIntStatus(UART1_BASE, true);
// Clear the asserted interrupts.
ROM_UARTIntClear(UART1_BASE, ulStatus);
// 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));
}
}
// 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(UART1_BASE, *pucBuffer++);
}
}
int
main(void)
{
// Enable lazy stacking for interrupt handlers. This allows floating-point
// instructions to be used within interrupt handlers, but at the expense of
// extra stack usage.
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 peripherals used by this example.
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
// Enable processor interrupts.
ROM_IntMasterEnable();
// Set GPIO A0 and A1 as UART pins.
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);
UARTSend((unsigned char *)"Enter text: ", 12);
while(1)
{
}
}
---------------------------------------------------------------------------------------