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.

How to enable Tiva-c launchpad UART1 Tx/Rx interrupt ?

Other Parts Discussed in Thread: TM4C123GH6PM

Hello ,

Im trying to send some data via UART1 serial from tiva-c launchpad and it seems like the data is send but the interrupt is not called.

Here is my code

#include <stdbool.h>
#include <stdint.h>
#include <inc/hw_memmap.h>
#include <driverlib/sysctl.h>
#include <driverlib/gpio.h>
#include <inc/hw_ints.h>
#include <driverlib/interrupt.h>
#include <driverlib/uart.h>
#include "driverlib/pin_map.h"

void UARTIntHandler(void);

int main()
{
        int data=1;

        SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

        //enable peripheral clock for UART0
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

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

        //disable UART0
        UARTDisable(UART1_BASE);

        //configure divisor and format
        UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 2400, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

        //enable FIFO
        UARTFIFOEnable(UART1_BASE); //is enabled automatically when UARTEnable() is called

        //enable individual UART interrupt source
        UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);

        //enable UART0 interrupt
        UARTIntRegister(UART1_BASE, UARTIntHandler);
        //IntEnable(INT_UART0);

        //enable processor interrupt
        IntMasterEnable();

        //enable UART0
        UARTEnable(UART1_BASE);

        UARTCharPut(UART1_BASE,data) ;

        while(1);
}


void UARTIntHandler(void)
{
        uint32_t UIstatus = UARTIntStatus(UART0_BASE, true);
        UARTIntClear(UART0_BASE, UIstatus);
}

  • Add a call to:

       IntEnable(INT_UART0);

    You actually must enable interrupts at three levels, the peripheral (UARTIntEnable();), the VIM (IntEnable();) and the CPU (IntMasterEnable();).

  • Hello Bob ,

    I have modified my code but the IntEnable do not solved this. The thing was that i had connected to PB1( Tx ) and PB0( Rx ) pins two wires from a Logic analyzer and it seems like the interrupt is not called if  the pins are connected to the wires. Nevertheless i also activated all kinds of uart interrupts, i will let here my new code. The question is why the interrupt is now called but not with Tx reason and why if i connected the wires to PB1 and PB0 pins the interrupt is not called anymore. Also a thing to know is that im using an tiva-c with an tm4c123gh6pm microcontroller.

    #include <stdbool.h>
    #include <stdint.h>
    #include <inc/hw_memmap.h>
    #include <driverlib/sysctl.h>
    #include <driverlib/gpio.h>
    #include <inc/hw_ints.h>
    #include <driverlib/interrupt.h>
    #include <driverlib/uart.h>
    #include "driverlib/pin_map.h"
    
    void UARTIntHandler(void);
    
    volatile int flag = 1 ;
    
    int main()
    {
            int data=1;
    
            SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    
            //enable peripheral clock for UART0
            SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
            SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    
            GPIOPinConfigure( GPIO_PB0_U1RX );
            GPIOPinConfigure( GPIO_PB1_U1TX );
            GPIOPinTypeUART( GPIO_PORTB_BASE , GPIO_PIN_0 | GPIO_PIN_1 );
    
            //disable UART0
            UARTDisable(UART1_BASE);
    
            //configure divisor and format
            UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 2400, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    
            //enable FIFO
            UARTFIFOEnable(UART1_BASE); //is enabled automatically when UARTEnable() is called
    
            //enable individual UART interrupt source
            UARTIntEnable(  UART1_BASE, UART_INT_DMATX |
           						UART_INT_DMARX      |
           						UART_INT_9BIT       |
           						UART_INT_OE         |
           						UART_INT_BE         |
           						UART_INT_PE         |
           						UART_INT_FE         |
           						UART_INT_RT         |
           						UART_INT_TX         |
           						UART_INT_RX         |
           						UART_INT_DSR        |
           						UART_INT_DCD        |
           						UART_INT_CTS        |
           						UART_INT_RI         );
    
            UARTIntRegister(UART1_BASE, UARTIntHandler);
    
            //enable processor interrupt
            IntMasterEnable();
    
            IntEnable(INT_UART1);
    
            UARTEnable(UART1_BASE);
    
            UARTCharPut(UART1_BASE,data) ;
    
            while(1);
    }
    
    
    void UARTIntHandler(void)
    {
            uint32_t UIstatus = UARTIntStatus(UART1_BASE, true);
            UARTIntClear(UART1_BASE, UIstatus);
    
            flag = 0 ;
    }

    Here you can see why the interrupt is called

  • The interrupt status flags you are receiving are Break error, Framing error and Receive time out. That makes me suspect that you do not have a valid signal attached to PB0. Is it left floating? When you have a logic analyzer attached to that pin, the leakage current from the logic analyzer input probably keeps the level high enough that it does not trigger the UART RX.

  • You are not getting a TX interrupt because you are using the FIFO mode with the FIFO level set to 1/2. That means you will get a TX interrupt when the level of the TX FIFO goes from 9 characters left to transmit to 8 characters left to transmit (8 empty spots in the TX FIFO). In your example, you never attempt to transmit more than one character. Therefore the FIFO never goes above half full, so it never generates an interrupt for transitioning from above half full to half full. If you want to generate a TX interrupt when the last character has completed transmission, then call:

            UARTTxIntModeSet(UART1_BASE, UART_TXINT_MODE_EOT);