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.

  • Resolved

UART Interrupt only works once (LM3S1968)

Hey there,

 I have a problem with my UART Interrupt, it only works once, if I want it to work again I'll have to reset the program.

 

//Set UART0

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 11500, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);

    UARTEnable(UART0_BASE);

    UARTIntEnable(UART0_BASE, UART_INT_RX);

    UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX1_8,

                 UART_FIFO_RX1_8);

 

void

UARTHandler(void)

{

    unsigned long ulStatus;

    //

    // Get the interrrupt status.

    //

    ulStatus = UARTIntStatus(UART0_BASE, true);

    //

    // Clear the asserted interrupts.

    //

    UARTIntClear(UART0_BASE, ulStatus);

    recTimer0 = 0;  

    recTimer1 = 0;  

}

 

recTimer0 and recTimer 1 are counters.

Did I forget anything to make it work more then once?

 

Any help is greatly appreciated!

  • Hi

    I noticed some minor differences to my code.

    void uart_init(void)
    {
        // Enable the peripherals used by this example.
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

        // Set GPIO A0 and A1 as UART pins.
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

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

        // Enable the UART interrupt.
        IntEnable(INT_UART0);
        UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
    }

    My interrupt handler implements a simple echo function.

    void UARTIntHandler(void)
    {
        unsigned long ulStatus;
        long lInChar = 0;
        static unsigned int uiIndex = 0;

        // Get the interrupt status.
        ulStatus = UARTIntStatus(UART0_BASE, true);

        // Clear the asserted interrupts.
        UARTIntClear(UART0_BASE, ulStatus);

        // Loop while there are characters in the receive FIFO.
        while(UARTCharsAvail(UART0_BASE))
        {
            // save the received character
            lInChar = UARTCharGetNonBlocking(UART0_BASE);

            // if echo mode is enabled then ...
            if(g_bRS232echo == TRUE){
                // ... read the available character and write it back to the UART
                UARTCharPutNonBlocking(UART0_BASE, lInChar);
            } else {
                // ... or append character to buffer
                g_cUARTBuffer[uiIndex++] = lInChar;

                // no overflow
                if(uiIndex >= 19){
                    uiIndex = 0;
                }
            }
        }

        // if whole string has been received reset the buffer index and set a flag
        if(('\n' == (char)lInChar) && (TRUE == g_bRS232echo)){
            g_bLoopbackTestPass = TRUE;
            uiIndex = 0;
        }
    }

     

    The important part in the IntHandler is definitly to reset the interruptPendingFlag.

     

    regards,

    cee

     

     

    __________________________________________________

    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are,
    by definition, not smart enough to debug it.  -- Brian Kernighan

  • In reply to cee:

    I'm sorry, but what do you mean by interruptPendingFlag?

    I don't see that anywhere in your code

  • In reply to nicoleschroder:

    Apparantly the UART is very unhappy if you don't read all chars available before leaving the ISR.

    so 

        // Loop while there are characters in the receive FIFO.

        while(UARTCharsAvail(UART0_BASE))

        {

            // save the received character

            lInChar = UARTCharGetNonBlocking(UART0_BASE);

        }

    pretty much fixed it for me!

     

    Thanks for your help :)

  • In reply to nicoleschroder:

    Hi Nicole,


    Sorry I did not make my self clear. By clearing the IntPendingFlag I meant that you have to call 'UARTIntClear(UART0_BASE, ulStatus);'

    What you actually do in your code.

    __________________________________________________

    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are,
    by definition, not smart enough to debug it.  -- Brian Kernighan

  • In reply to cee:

    Ah, yea that makes sense!

    Thanks for the code example, it's fixed now :)

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.