No UART transmission LPC1343

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

No UART transmission LPC1343

Jump to solution
1,402 Views
deboogle
Contributor I

I am trying to get the UART working on the LPC1343 at chip level and I have the PIO1_6 and PIO1_7 connected to an FTDI device which is plugged into my PC running putty.  When I run the board level ring buffer example the UART is working and I see the output in putty, but when I try my chip level code, nada!

I created a project using the wizard and then added the following lines of code:

Chip_IOCON_PinMuxSet(LPC_IOCON,IOCON_PIO1_6,(IOCON_FUNC1 | IOCON_RESERVED_BIT_6 | IOCON_RESERVED_BIT_7 | IOCON_MODE_INACT));


Chip_IOCON_PinMuxSet(LPC_IOCON,IOCON_PIO1_7,(IOCON_FUNC1 | IOCON_RESERVED_BIT_6 | IOCON_RESERVED_BIT_7 | IOCON_MODE_INACT));

Chip_UART_Init(LPC_USART);
Chip_UART_SetBaud(LPC_USART, 115200);
Chip_UART_TXEnable(LPC_USART);

val = Chip_UART_Send(LPC_USART, "Test\n", 5);

after completion the returned value is 1 and i would have expected 5 as this is how many should have been placed into the buffer.

When I step through the code I can see the various characters being moved in but nothing is coming out of the terminal application?

Can anyone enlighten me as to what I have missed please? I am new to LPCopen having previously doen everything at register level using CMSIS only.

Labels (2)
0 Kudos
Reply
1 Solution
1,041 Views
deboogle
Contributor I

Hi Kerry,

The first thing I found was that I had not enabled the peripheral clock.  Once I did that I found it only transmitted the first byte until I added the extra while statement as you suggested:

    /* Send until the transmit FIFO is full or out of bytes */
/*    while ((sent < numBytes) &&
           ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) != 0)) {
        Chip_UART_SendByte(pUART, *p8);
        p8++;
        sent++;
    }*/

 

    while ((sent < numBytes) ) {
        while((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) == 0);
        Chip_UART_SendByte(pUART, *p8);
        p8++;
        sent++;
    }

 

    return sent;
}

As obviously in its original incarnation will only send the first byte.

All working now many thanks.

Many thanks

View solution in original post

0 Kudos
Reply
3 Replies
1,041 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hello David,

  Please follow my step and try it on your side.

  Please still modify the code based on the orignial periph_uart_rb code.

  You can just call :val = Chip_UART_Send(LPC_USART, "Test\n", 5);

 Then modify the Chip_UART_Send like this:

/* Transmit a byte array through the UART peripheral (non-blocking) */
int Chip_UART_Send(LPC_USART_T *pUART, const void *data, int numBytes)
{
    int sent = 0;
    uint8_t *p8 = (uint8_t *) data;

    /* Send until the transmit FIFO is full or out of bytes */
/*    while ((sent < numBytes) &&
           ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) != 0)) {
        Chip_UART_SendByte(pUART, *p8);
        p8++;
        sent++;
    }*/

    while ((sent < numBytes) ) {
        while((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) == 0);
        Chip_UART_SendByte(pUART, *p8);
        p8++;
        sent++;
    }

    return sent;
}

I have test it on my side, I can get the test printf data on my side:

pastedImage_1.png

My main code is:

int main(void)
{
    uint8_t key;
    int bytes;
    int val=0;
    /* Generic Initialization */
    SystemCoreClockUpdate();
    Board_Init();
    Init_UART_PinMux();
    Board_LED_Set(0, false);

    /* Setup UART for 115.2K8N1 */
    Chip_UART_Init(LPC_USART);
    Chip_UART_SetBaud(LPC_USART, 115200);
    Chip_UART_ConfigData(LPC_USART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));
    Chip_UART_SetupFIFOS(LPC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));//UART_FCR_TRG_LEV2
    Chip_UART_TXEnable(LPC_USART);

    /* Before using the ring buffers, initialize them using the ring
       buffer init function */
    RingBuffer_Init(&rxring, rxbuff, 1, UART_RRB_SIZE);
    RingBuffer_Init(&txring, txbuff, 1, UART_SRB_SIZE);

    /* Enable receive data and line status interrupt, the transmit interrupt
       is handled by the driver. */
    Chip_UART_IntEnable(LPC_USART, (UART_IER_RBRINT | UART_IER_RLSINT));

    /* preemption = 1, sub-priority = 1 */
    NVIC_SetPriority(UART0_IRQn, 1);
    NVIC_EnableIRQ(UART0_IRQn);

    /* Send initial messages */
//    Chip_UART_SendRB(LPC_USART, &txring, inst1, sizeof(inst1) - 1);
//    Chip_UART_SendRB(LPC_USART, &txring, inst2, sizeof(inst2) - 1);

    val = Chip_UART_Send(LPC_USART, "Test\n", 5);

    /* Poll the receive ring buffer for the ESC (ASCII 27) key */
    key = 0;
    while (key != 27) {
        bytes = Chip_UART_ReadRB(LPC_USART, &rxring, &key, 1);
        if (bytes > 0) {
            /* Wrap value back around */
            if (Chip_UART_SendRB(LPC_USART, &txring, (const uint8_t *) &key, 1) != 1) {
                Board_LED_Toggle(0);/* Toggle LED if the TX FIFO is full */
            }
        }
    }

    /* DeInitialize UART0 peripheral */
    NVIC_DisableIRQ(UART0_IRQn);
    Chip_UART_DeInit(LPC_USART);

    return 1;
}

Please try this at first, after it works on your side, then modify the chip initialization and test again.

Any question, please let me know!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,042 Views
deboogle
Contributor I

Hi Kerry,

The first thing I found was that I had not enabled the peripheral clock.  Once I did that I found it only transmitted the first byte until I added the extra while statement as you suggested:

    /* Send until the transmit FIFO is full or out of bytes */
/*    while ((sent < numBytes) &&
           ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) != 0)) {
        Chip_UART_SendByte(pUART, *p8);
        p8++;
        sent++;
    }*/

 

    while ((sent < numBytes) ) {
        while((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) == 0);
        Chip_UART_SendByte(pUART, *p8);
        p8++;
        sent++;
    }

 

    return sent;
}

As obviously in its original incarnation will only send the first byte.

All working now many thanks.

Many thanks

0 Kudos
Reply
1,041 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hello David,

   You are welcome!

  If your question is solved, please help me to close this post by marking the correct answer, thank you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply