Skip to main content
Visitor II
June 6, 2006
Question

UART Problem

  • June 6, 2006
  • 1 reply
  • 582 views
Posted on June 06, 2006 at 10:27

UART Problem

    This topic has been closed for replies.

    1 reply

    Visitor II
    June 6, 2006
    Posted on June 06, 2006 at 10:27

    Hi, I am having some trouble with UARTs. It happens not very often, but it happens.

    I am using the 4 UARTs. In the middle of a data transfer through UART3, (half duplex, which sends some data, waits ACK, sends more data, and so on..) it suddenly hangs my application. By making some debug with JTAG, I noticed that UART0 enters in the interrupt routine countinously (as if some interrupt bit is always set), but I dont know why. These are the values of some registers I got from UART0:

    CR: 0x05A9

    IER: 0x0140

    SR: 0x0006

    My communication module (the one who handles the 4 UARTs) is using interrupts and FIFOs. It just makes some buffering of data.

    This code is the ISR:

    Code:

    static void CommISRHandler(commbuffer_t *pBuffer, UART_TypeDef *UARTx)

    {

    uint16_t FlagStatus;

    uint16_t nError;

    FlagStatus = UART_FlagStatus(UARTx) & UARTx->IER;

    /* Check any TX Interrupt */

    if (FlagStatus & (UART_TxEmpty | UART_TxHalfEmpty)) {

    do {

    /* Is there any data to send? */

    if (0 == pBuffer->BufferTxCtr) {

    /* No, so turn off TX interrupts */

    UART_ItConfig(UARTx, UART_TxEmpty | UART_TxHalfEmpty, DISABLE);

    break;

    }

    /* Put new data */

    UARTx->TxBUFR = CommGetCharISR(pBuffer, &nError);

    /* Repeat until UART is full */

    } while (UART_FlagStatus(UARTx) & UART_TxFull);

    }

    /* Check any RX Interrupt */

    if (FlagStatus & (UART_RxHalfFull | UART_TimeOutNotEmpty)) {

    do {

    /* Add Data to Buffer */

    CommPutCharISR(pBuffer, UARTx->RxBUFR);

    /* UART_RxBufFull in fact means UART_RxBufNotEmpty */

    /* So, repeat until no data is present */

    } while (UART_FlagStatus(UARTx) & UART_RxBufFull);

    }

    }

    The ISR has two parameters:

    commbuffer_t *pBuffer -> points to the corresponding buffer structure

    UART_TypeDef *UARTx -> points to corresponding UART

    My 4 UART Interrupt handlers only call this routine, for instance:

    Code:

    void Comm0ISR(void)

    {

    CommISRHandler(Buffers[0], UART0);

    return;

    }

    Any suggestion?

    Regards,