UART0 on LPC11U68

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

UART0 on LPC11U68

1,765件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by williamjsell on Fri Nov 20 15:06:37 MST 2015
I am struggling to get the UART0 peripheral to work on the LPC11U68.  The problem is getting an interrupt generated when the THR is empty.  Should be simple no?  To just try a simple test, I have configured the UART0 to send out a single character after being initialized.  The nterrupt is called, but the status of the interrupt makes no sense.  When I read the IIR status register inside the interrupt:

    uint32_t status = Chip_UART0_ReadIntIDReg(LPC_USART0);

the value of status is 0xC1.  0x1 indicates "no interrupt pending".  I was expecting to see on the INTID a value of 1, to indicate the THR is empty and ready for another byte.  This is required to start the state machine running.  The 0xC value indicates the FIFO is enabled with 1 character depth. 

Any ideas on what is going on?


bool
xMBPortSerialInit(uint32_t ulBaudRate, eMBParity eParity)
{
//set debug pin as an output
    bool  bInitialized = pdTRUE;
    //UART signals on pins PIO0_14 (FUNC4, U1_TXD) and PIO0_13 (FUNC4, U1_RXD)
    //NOTE: The port initialization is not part of the modbus library.  This allows other
    //processors to be used with the Modbus library. 
Chip_IOCON_PinMuxSet(LPC_IOCON, IOP_GETPORTNUM(pindef_CALRXD), IOP_GETPINNUM(pindef_CALRXD), (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, IOP_GETPORTNUM(pindef_CALTXD), IOP_GETPINNUM(pindef_CALTXD), (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
    Chip_UART0_Init(LPC_USART0);
    Chip_UART0_SetBaud(LPC_USART0, 115200);
/* Enable receive data and line status interrupt */
Chip_UART0_IntEnable(LPC_USART0, (UART0_IER_RBRINT | UART0_IER_THREINT));
    Chip_UART0_ConfigData(LPC_USART0, (UART0_LCR_WLEN8 | UART0_LCR_SBS_1BIT | UART0_LCR_PARITY_DIS));
/* Enable UART 0 interrupt */
NVIC_EnableIRQ(USART0_IRQn);
    //stop bits are 1 by default, 2 if no parity is used

    //a simple test
    xMBPortSerialPutByte(0x10);

    return bInitialized;
}
ラベル(1)
1 返信

1,162件の閲覧回数
sirurx
Contributor III

Hi,

Got things working? USART0 is different from USART1-4.

Be sure to enable clocks:

Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);

Chip_GPIO_Init(LPC_GPIO);

Then:

Chip_IOCON_PinMuxSet(LPC_IOCON, Port, Pin, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));

Chip_IOCON_PinMuxSet(LPC_IOCON, Port, Pin, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));

//Where Port and pins are dependent on your HW, and FUNC1 is just an assumption too here. See actual table from user manual.

Init:

Chip_UART0_Init(LPC_USART0);

Chip_UART0_SetBaud(LPC_USART0, 115200);

Chip_UART0_ConfigData(LPC_USART0, (UART0_LCR_WLEN8 | UART0_LCR_SBS_1BIT));

Chip_UART0_TXEnable(LPC_USART0);

Chip_UART0_IntEnable(LPC_USART0, UARTN_INTEN_RXRDY);

NVIC_EnableIRQ(USART0_IRQn);

Then inteerupt appears on RX byte.

In interrupt handler you should do smth like this:

IIRValue = LPC_USART0->IIR;

    if(IIRValue & UART0_IIR_INTID_RLS)

    {

        LSRValue = LPC_USART0->LSR;

        if (LSRValue & (LSR_OE | LSR_PE | LSR_FE | LSR_RXFE | LSR_BI))

        {

            Dummy = (uint8_t)LPC_USART0->RBR;    // Dummy read on RX to clear interrupt

            return;

        }

        if (LSRValue & LSR_RDR)    // Receive Data Ready

        {

            variable = ((uint8_t)LPC_USART0->RBR);

        }

    }

    else if(IIRValue & UART0_IIR_INTID_RDA)

    {

        variable = ((uint8_t)LPC_USART0->RBR);

    }

BR,

Ergo