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.

UART0 RX Interrupt not firing

Hi,

maybe someone can help me see, what I am doing wrong or where I am missing something.

I want to do a UART communication based on interrupts. I have verified that the communication line to the pc is establishe by manually sending Bytes from the MCU to the PC via the function UARTCharPut and that worked so far.

Now I want to receive a Byte from the PC and handle it in the Interrupt. I'm doing this via a simple terminal program. I also can see the char in the UART_DR Buffer with no errors displayed in the same register. I did this while letting the debugger run and had a breakpoint in the RXTX_Interrupt Handler. The problem is: This interrupt did not fire.

(The UART_IM_RXIM was set in the UART_IM Register with no other Interrupts masked). The condensed code of my example is posted below. A few lines are redundand and it will be cleaned up after I get the UART Interrupt working. The UART0_RXTXHandler is registered in the startup_ccs. I am using CCS 5.2, lm4f232 on the eval board.

 void main (void)

{

SysCtlClockSet(
   SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ
     | SYSCTL_OSC_MAIN);

 SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

 SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

 GPIOPinConfigure(GPIO_PA0_U0RX);
 GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0); // Enable port PA0 for UART0 U0RX
 GPIOPinConfigure(GPIO_PA1_U0TX);
 GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_1); // Enable port PA1 for UART0 U0TX

 const uint16_t u_def_Baud = 9600; //Select BBaud Rate here
 UARTDisable(UART0_BASE); //disable for configuration
 UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), u_def_Baud,
   (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
 UARTFlowControlSet(UART0_BASE, UART_FLOWCONTROL_NONE);

 UARTFIFODisable(UART0_BASE);
 UARTIntClear(UART0_BASE, UART_INT_RX);
 UARTIntClear(UART0_BASE, UART_INT_TX);
 IntEnable(UART_INT_RX);
 IntEnable(UART_INT_TX);

 IntMasterEnable(); //enable Interrupts 

UART0_TX_Start();
 UARTCharPut(UART0_BASE, 0x4a);
 while (UARTBusy(UART0_BASE));
 UART0_RX_Start();

while(1);

}

void UART0_RX_Start(void)
{
 UARTDisable(UART0_BASE);
 UARTIntClear(UART0_BASE, UART_INT_TX);
 UARTIntDisable(UART0_BASE, UART_INT_TX);
 UARTIntEnable(UART0_BASE, UART_INT_RX);
 UARTEnable(UART0_BASE);
}

void UART0_TX_Start(void)
{
 UARTDisable(UART0_BASE);
 UARTIntClear(UART0_BASE, UART_INT_RX);
 UARTIntDisable(UART0_BASE, UART_INT_RX);
 UARTIntEnable(UART0_BASE, UART_INT_TX);
 UARTEnable(UART0_BASE);
}

void UART0_RXTXHandler(void)
{
 uint8_t ub_RXReady = 0;
 uint8_t ub_TXReady = 0;
 ub_RXReady = UARTCharsAvail(UART0_BASE);
 ub_TXReady = UARTBusy(UART0_BASE);

 UARTIntClear(UART0_BASE, UART_INT_RX);

 UARTIntClear(UART0_BASE, UART_INT_TX);

 if (ub_RXReady == TRUE) //We have received something
 {

  USART_RX_Telegramm_Standard();

 }
 else if (ub_TXReady == TRUE) //Transmit Buffer is empty.
 {
  USART_TX_Telegramm_Standard();
 }
 else //keins von beiden??
 {

 }

}

 

 * added the line for FIFO Disabling, but still no change

 

 

  • Hi Jan,

    I'm sorry to hear that you're having trouble getting your UART to work.  The first thing I would do before making any modifications to your code is to try running the uart_echo example project.  For the lm4f232, you can find this in your StellarisWare install directory at StellarisWare/boards/ek-lm4f232/uart_echo.  This program is a pretty simple example that sets up the system clock, enables the UART and necessary GPIO blocks, does a simple print to the UART, then echoes back anything it receives by way of an interrupt handler.  I think there's also some graphic display stuff to give the UART parameters on the OLED that the ek comes with, but for your purposes you should be able to pretty much ignore any of the functions calls that start with Gr.

    With a quick glance at your code, though, I'm guessing that there's an issue with how you're enabling interrupts.  The IntEnable() function is normally used to enable interrupts on a peripheral by peripheral basis, as opposed to enabling a specific type of interrupt on a peripheral.  To enable or disable an individual interrupt inside the peripheral, there normally exists a separate <PERIPHERAL>IntEnable function.  So for your example, you would want to the following:

    IntEnable(INT_UART0);
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    If that doesn't work, or if you're not able to find the uart_echo example, let me know and I'll see what else I can do to help!

  • Hi Jordan,

    thanks for your help. The example worked. It seems the problem was the IntEnable(INT_UART0), which I called with a wrong parameter. I got the receive Interrupt working now and will be able to continue from there.

  • As a follow up, I got my communication fully working now with the disabled FIFO. However I was not able to make the Transmit Interrupt work by using only the stellarisware functions. Therefore when I wanted to disable the RX I added the lines following lines, because the UARTEnable Function always enables Rx AND Tx.

     UARTDisable(UART0_BASE);
     UARTIntClear(UART0_BASE, UART_INT_RX);
     UARTFIFODisable(UART0_BASE);
     UARTIntDisable(UART0_BASE, UART_INT_RX);
     UARTIntDisable(UART0_BASE, UART_INT_RT);   //is activated by default! Would generate interrupt if not disabled
     IntEnable(INT_UART0);
     UARTIntEnable(UART0_BASE, UART_INT_TX);
     while (UARTBusy(UART0_BASE))
     {

     }
    // UARTEnable(UART0_BASE);   //enables RX and TX therefore not called here.
     HWREG(UART0_BASE + UART_O_CTL) &= ~(UART_CTL_RXE); //disables RX
     HWREG(UART0_BASE + UART_O_CTL) |= (UART_CTL_UARTEN | UART_CTL_TXE); //enables UART and TX