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.

Uart3 interrupt not working



Hello,

Hello, I'm trying to use UART1, UART3  on my stellaris launchpad but UART3 interrupt is not working.

I can send and receive messages on UART1 but on UART3 I can only send the messages.

I use CCS.

Here is my code:

void UART1IntHandler(void)
{
volatile unsigned long ulStatus;
volatile unsigned char fromUART;

ulStatus = UARTIntStatus(UART1_BASE, true);
UARTIntClear(UART1_BASE, ulStatus);
while(UARTCharsAvail(UART1_BASE))
{
fromUART = UARTCharGetNonBlocking(UART1_BASE);

}
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
SysCtlDelay(SysCtlClockGet() / 5 / 3);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
SysCtlDelay(SysCtlClockGet() / 5 / 3);
}

void UART3IntHandler(void)
{
volatile unsigned long ulStatus;
volatile unsigned char fromUART;

ulStatus = UARTIntStatus(UART3_BASE, true);

UARTIntClear(UART3_BASE, ulStatus);
if (command.exCmd==FALSE)
{
while(UARTCharsAvail(UART3_BASE))
{
fromUART = UARTCharGetNonBlocking(UART3_BASE);
}
}
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3);
SysCtlDelay(SysCtlClockGet() / 5 / 3);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0);
SysCtlDelay(SysCtlClockGet() / 5 / 3);

}

void main(void) {
unsigned long Debug;
unsigned long ulStatus;
//
// 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.
//
FPUEnable();
FPULazyStackingEnable();

//
// Set the clocking to run directly from the crystal.
//
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.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

//
// Enable the GPIO pins for the LED (PF2).
//
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);

GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1);
GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_4);

//
// Enable the peripherals used by this example.
//
// SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);

IntMasterEnable();

// SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

//
// Set GPIO A0 and A1 as UART pins.
//

GPIOPinConfigure(GPIO_PB0_U1RX);
GPIOPinConfigure(GPIO_PB1_U1TX);
GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

GPIOPinConfigure(GPIO_PC6_U3RX);
GPIOPinConfigure(GPIO_PC7_U3TX);
GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);

//
// Configure the UART for 115,200, 8-N-1 operation.
//
UARTConfigSetExpClk(UART3_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//
// Enable the UART interrupt.
//
ulStatus = UARTIntStatus(UART1_BASE, true);
UARTIntClear(UART1_BASE, ulStatus);
ulStatus = UARTIntStatus(UART3_BASE, true);
UARTIntClear(UART3_BASE, ulStatus);
IntEnable(INT_UART1);
UARTIntEnable(UART1_BASE, UART_INT_RT | UART_INT_RX);
IntEnable(INT_UART3);
UARTIntEnable(UART3_BASE, UART_INT_RT | UART_INT_RX);

for(;;) {

UARTSend(UART1_BASE,(unsigned char*)command.msg, 3);
UARTSend(UART3_BASE,(unsigned char*)command.msg, 3);
SysCtlDelay(2000000);

}

The interrupt functions are registered in startup_ccs.c. I copied only the related parts. See bellow:

extern void UART1IntHandler(void);
extern void UART3IntHandler(void);

.

.

.

IntDefaultHandler, // UART0 Rx and Tx
UART1IntHandler, // UART1 Rx and Tx
IntDefaultHandler, // SSI0 Rx and Tx

.

.

IntDefaultHandler, // SSI3 Rx and Tx
UART3IntHandler, // UART3 Rx and Tx
IntDefaultHandler, // UART4 Rx and Tx

Thank You!

  • Hi,

    According to your UART3Interrupt handler, you can receive something only if command.exCmd==FALSE, so what is the value of this variable? did you used the debugger to find out? 

    Second, the delays are too big inside interrupt handlers, try to remove them, they are not needed.

    Petrei

  • Hello,

    thanks for your answer. To blink the leds are only for debug.

    If I make short between the PB0, PB1 I can see that the blue led is blinking, but if I made a short between the PC6, PC7 I can not see that the green works.

    I tried an other board and it is working well. So It looks it was board issue.

    Thanks for the advice

  • after

    GPIOPinConfigure(GPIO_PC6_U3RX);
    GPIOPinConfigure(GPIO_PC7_U3TX);
    GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);

    write:

    GPIOPinConfigure(GPIO_PC6_U3RX);
    GPIOPinConfigure(GPIO_PC7_U3TX);
    GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);

    GPIOPadConfigSet(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);

    ;)

    the same in UART1

  • Jorge Alejandro said:

    after...

    GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);

    write...

    GPIOPadConfigSet(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);

    Or not - key here is to better read/review, "GPIOPinTypeUART" (extracted below)  Note that the function addition you suggest is included w/in the initial function.  Most all such StellarisWare functions may be reviewed in detail w/in: StellarisWare\driverlib\

    void
    GPIOPinTypeUART(unsigned long ulPort, unsigned char ucPins)
    {
        //
        // Check the arguments.
        //
        ASSERT(GPIOBaseValid(ulPort));

           // Make the pin(s) be peripheral controlled.
        GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);

         // Set the pad(s) for standard push-pull operation.
        GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
    }

    Feel not bad - many order such "duplicate" functions.  Your coding makes output tad stronger & adds pull-up - but our testing finds this is not needed...  (as did LMI - creators of StellarisWare...)