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.

Break and Frame error on UART enable



I am trying to configure UART1 of TM4C123FH6PMI for receiving bytes. As soon as UART is enabled, break and frame error are reported on Status register. This happens though no bytes are sent to microcontroller's UART. Here is my UART configuration code, can somebody point out, what is going wrong? This source code uses TivaWare APIs at places.

{

IntDisable(INT_UART1);

SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART1);

//
// Configure hardware pins and UART control register
GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
GPIOPinConfigure(GPIO_PB0_U1RX);
GPIOPinConfigure(GPIO_PB1_U1TX);

UARTFIFODisable(UART1_BASE);

//
// Enable the UART peripheral interrupts. Note that no UART interrupts
// were enabled, but the uDMA controller will cause an interrupt on the
// UART interrupt signal when a uDMA transfer is complete.
//
IntEnable(INT_UART1);
UARTIntEnable(UART1_BASE, UART_INT_RX); 

//
// Configure the UART communication parameters.
//

uint32_t ui32Baud = 38400U;
uint32_t ui32Div;
//
// Is the required baud rate greater than the maximum rate supported
// without the use of high speed mode?
//
if((38400U* 16) > SysCtlClockGet())
{
//
// Enable high speed mode.
//
HWREG(UART1_BASE+ UART_O_CTL) |= UART_CTL_HSE;

//
// Half the supplied baud rate to compensate for enabling high speed
// mode. This allows the following code to be common to both cases.
//
ui32Baud /= 2;
}
else
{
//
// Disable high speed mode.
//
HWREG(UART1_BASE+ UART_O_CTL) &= ~(UART_CTL_HSE);
}

//
// Compute the fractional baud rate divider.
//
ui32Div = (((SysCtlClockGet() * 8) / ui32Baud) + 1) / 2;

//
// Set the baud rate.
//
HWREG(UART1_BASE+ UART_O_IBRD) = ui32Div / 64;
HWREG(UART1_BASE+ UART_O_FBRD) = ui32Div % 64;

//
// Set parity, data length, and number of stop bits.
//
HWREG(UART1_BASE+ UART_O_LCRH) = UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE;

//
// Clear the flags register.
//
HWREG(UART1_BASE+ UART_O_FR) = 0;

HWREG(UART1_BASE+ UART_O_CTL) |= (UART_CTL_UARTEN | UART_CTL_TXE |
UART_CTL_RXE);

}

  • Hello Bhaskar

    Why complicated when simple solutions are there? First of all before configuring the UART you need to disable the UART module. And what it is worth all the lines of code can be replaced by UARTConfigSetExpClk function!!!

    Regards
    Amit
  • Amit Ashara said:
    Why complicated when simple solutions are there?

    So, so true - and these eased, faster solutions are often desribed as, "KISS."      And - when the MCU maker is so kind & helpful as to provide complete, exhaustively test/verified "key functions" - makes little sense to, "roll or assemble your own."       ("UARTConfigSetExpClk()" serves as a perfect example!)

    May prove of interest to learn, "why" this poster chose to avoid, "UARTConfigSetExpClk()" and launch his own.     Diagnostic crue must, "give thanks" that "direct register" was not "too much" in play - yet this begs the question as to "how" this hybrid mix (direct register & "portions" of the API) came into being...

  • Thanks for your replies.
    Ok. Let me back up a bit. This complex hybrid stuff evolved out of trials to make UART work. Basically, executing UARTConfigSetExpClk() was throwing up Break condition and Frame error on this UART module. I replaced UARTConfigSetExpClk() call with the function definition from the library to see whats going wrong. So what I observed was this routine enables UART at the end and that is when the Break and Frame Errors come up. The other UART, UART0 on this controller works without this problem. So here is how my code looks like:

    {

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

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

    UARTEnable(UART1_BASE);

    }
  • May I acknowledge yours as a very well directed reply?    Your "hybrid creation" makes sense (now) under the conditions you describe.

    I've been at this forum for a bit - cannot recall another report of "UART - Break & Frame error" immediately upon enable!

    May I "guess" that your UART_RX pin is "floating?"    Such may well cause (both) Break & Frame error (and possibly) others.

    For the record - many, many here have succeeded w/"plain vanilla" API calls.   

    Note that the code your most recent post reveals fails to properly "Peripheral Enable" UART1.    (although it may occur earlier & elsewhere)

    You note that UART0 "behaves" - might that result from its (correct) termination w/in your (assumed) L-Pad?    (i.e. connected to ICDI MCU)

  • Hello Bhaskar

    My suspicion lies on what is connected to UART1RX pin since UART0 as mentioned in the post works fine.

    Secondly, to highlight that the code break done was not complete is the fact the UART Configuration starts with UARTDisable, which was missing in the code post.

    Lastly what is not clear is the clock source to the system (system clock frequency) , but my suspicion is way less on this in lieu of UART0 being functional.
    Regards
    Amit
  • You were right, UART RX was not on a right voltage level. I got that corrected. Also for setting up baud stuff an all, the UART disable had to be done after setting GPIO pins as UART TX/RX pins. 

    Thank you both for quick responses.

  • Thank you, Sir - appreciated.

    May I note that "green points" should double for beating the "master!" (if only by 3 minutes...) And we thought only Robert's clock slow...