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.

UART1 Module always enters to UART1_Handler even if there is no data in RX line

Hello 

I need to use UART1 Module in one application. I use Tiva TM4C123GXL Board. Thats why I activated UART1 Module. But the problem is that My code always enters to UART1_Handler and thats why my code does not enter main loop even if there are any data in RX pin of UART1 Module. The problem is same wirh UART3 Module too. But UART0 module works fine with same config

My UART initilization and Handler function in below

void UART1_Init(void)
{
  SYSCTL_RCGCUART_R |= 0x02;                            // Activate UART1
  SYSCTL_RCGCGPIO_R |= 0x02;                            // Activate port B
  UART1_CTL_R &= ~UART_CTL_UARTEN;                      // Disable UART
  UART1_IBRD_R = 260;                                   
  UART1_FBRD_R = 27;                                  

  UART1_LCRH_R = (UART_LCRH_WLEN_8 | UART_LCRH_FEN);    // 8 bit word length (no parity bits, one stop bit, FIFOs)

  UART1_IFLS_R &= ~0x3F;                                // Clear TX and RX interrupt FIFO level fields
                                                        // Configure interrupt for TX FIFO <= 1/8 full
                                                        // Configure interrupt for RX FIFO >= 1/8 full
  UART1_IFLS_R += (UART_IFLS_TX1_8|UART_IFLS_RX1_8);    // Enable TX and RX FIFO interrupts and RX time-out interrupt
  // UART1_IM_R |= (UART_IM_RXIM|UART_IM_TXIM|UART_IM_RTIM);
  UART1_IM_R  |= (UART_IM_RXIM | UART_IM_RTIM);         // UART Receive Interrupt Mask | UART Receive Time-Out Interrupt
  UART1_CTL_R |= UART_CTL_UARTEN;                       // Enable UART

  GPIO_PORTB_AFSEL_R |= 0x03;                           // Enable alt funct on PB1-0
  GPIO_PORTB_DEN_R   |= 0x03;                           // Enable digital I/O on PB1-0

  GPIO_PORTB_PCTL_R  = (GPIO_PORTB_PCTL_R&0xFFFFFF00)+0x00000011;  // Configure PB1-0 as UART
  GPIO_PORTB_AMSEL_R = 0;                                          // Disable analog functionality on PB

  NVIC_PRI1_R = (NVIC_PRI1_R&0xFFFF00FF)|0x00004000;               // UART0=priority 2, Bits 13-15
  NVIC_EN0_R = NVIC_EN0_INT6;                                      // Enable interrupt 6 in NVIC
}

void UART1_Handler(void)
{
    if(UART1_RIS_R&UART_RIS_RXRIS)
      {       // hardware RX FIFO >= 2 items
        UART1_ICR_R = UART_ICR_RXIC;        // acknowledge RX FIFO , RX Interrupt Clear
      }
}

Regards

Serkan

  • Hello Serkan,

    First of all please use TivaWare API's instead of DRM. This will make the code more readable for the rest of the forum.

    Next, do always try to send the project files instead of code snapshots so that we can see what is the setup of the vector table and if required run it on a LaunchPad.

    Regards
    Amit
  • Amit Ashara said:
    please use TivaWare API's instead of DRM. This will make the code more readable for the rest of the forum.

    So, so true, Amit.   Staff, clients & I all appreciate such proper direction.

    When posters choose such "harder path" - one that is NEVER, "Tried/True/Tested" (such as the API) - they fail to consider the EXTRA TIME & EFFORT forced upon you!   That is never good - nor fair to the rest of the forum!   (clearly reduces the number of your responses - penalizing MANY for the benefit of just ONE!)

    Posters who delight in "inviting hardship" (via use of DRM or ASM) should limit their (self-caused) pain/suffering to themselves.

    *** In poster's specific case - my sense is that his "tested" UART_RX lines were both allowed to "float" - causing those (unwanted) interrupts...

  • Hello Amit

    Thanks for ur recommendation. I will move to TivaWare API as soon as possible.

    Serkan
  • Hello cb1

    Yes problem is related with the pull-up resistance. I enabled weak pull-up resistance in software and problem is solved.

    Thanks..

    Serkan
  • Hello Serkan,

    So it seems that the driver of the UART1 does not have RX line high (Idle State of the UART Bus)!

    Regards
    Amit
  • Hello Amit,

    Indeed - as always "Unguided Posters" may present (some) needed data - but rarely (never) ALL needed data!

    The absence of such Guidelines - most predictably - leads to such data "shortages." This poster (did) provide much necessary data - yet not "sufficient" data - which a guideline would emphasize. (i.e. if a "key pin" does not perform as expected - "Identify any/all connections, logic level during idle states, and levels during operation" AND...Never/Ever allow a used MCU pin to float!)

    My firm happened to note UART_RXn "requiring" a logic high when we "shared" that UART between a combined RS232/485 level shifter & a CAN xcvr. That CAN xcvr "pulled down" the 232/485 (common) driver's "high" idle level - and the LX4F's UART (then) failed to perform.   (breaking the common connection between MCU's UART_RX  - RS232/485 shifter and CAN xcvr - - - so that the RS232/485 shifter could "pull-up" the MCU's UART_RX line - enabled the MCU's UART to perform...)