lpcware

LPCOpen LPC11U68 USART0 baudrate 1024000

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by dmitrij_zylkov on Wed Sep 02 04:23:22 MST 2015
Hello!
I have a problem with LPC11U68 USART0 baudrate configuration. Can somebody make clear what can be wrong with my code. When I set 1024000 baudrate for USART0 PC gets simbols on 2048000 baudrate and LPC11U68 USART0 unable to read them on this baud.


void UART_0_Init(void){   

    uint32_t tmp = 0;
    uint32_t actual_baudrate = 0;
    NVIC_DisableIRQ(USART0_IRQn);//Disable UART0 interrupts

    //Initialize receive ring buffer.
    memset(&uart_0_data_rx, 0, UART_0_DATA_RX_SIZE);
    ringbuf_init(&ring_uart_0_rx, (uint8_t*)&uart_0_data_rx, (uint8_t)UART_0_DATA_RX_SIZE);
    //Initialize transmit ring buffer
    memset(&uart_0_data_tx, 0, UART_0_DATA_TX_SIZE);
    ringbuf_init(&ring_uart_0_tx, (uint8_t*)&uart_0_data_tx, (uint8_t)UART_0_DATA_TX_SIZE);
   
//Initialize Rx and Tx pins
    /* UART signals on pins PIO0_19 (FUNC3, U0_TXD) and PIO0_18 (FUNC2, U0_RXD) */
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 18, (IOCON_FUNC1|IOCON_MODE_INACT));
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 19, (IOCON_FUNC1|IOCON_MODE_INACT));

    /* Setup UART for 115.2K8N1 */
    Chip_UART0_Init(LPC_USART0);
    Chip_UART0_SetBaud(LPC_USART0, USART_0_BAUDRATE);
    actual_baudrate = Chip_UART0_SetBaudFDR(LPC_USART0, USART_0_BAUDRATE);
    Chip_UART0_ConfigData(LPC_USART0, (UART0_LCR_WLEN8 | UART0_LCR_SBS_1BIT | UART0_LCR_PARITY_DIS));
    //Setup FIFO buffer for USART0
    Chip_UART0_SetupFIFOS(LPC_USART0, (UART0_FCR_FIFO_EN | UART0_FCR_RX_RS | UART0_FCR_TX_RS)); //  | UART0_FCR_TRG_LEV2
    Chip_UART0_TXEnable(LPC_USART0);
    /* Ensure a clean start, no data in either TX or RX FIFO.   */
    while (( LPC_USART0->LSR & (UART0_LSR_THRE | UART0_LSR_TEMT)) != (UART0_LSR_THRE | UART0_LSR_TEMT) );
    while ( LPC_USART0->LSR & UART0_LSR_RDR )
    {
        tmp = Chip_UART0_ReadByte(LPC_USART0);    /* Dump data from RX FIFO */
    }
    tmp |= tmp;
    /* Enable receive data and line status interrupt */
    Chip_UART0_IntEnable(LPC_USART0, (UART0_IER_RBRINT | UART0_IER_RLSINT | UART0_IER_THREINT));    //  | UART0_IER_THREINT

NVIC_SetPriority(USART0_IRQn, 3);
    /* Enable UART 0 interrupt */
    NVIC_EnableIRQ(USART0_IRQn);
//Start UART_0 task
    UART_0_TaskID = osThreadCreate(osThread (UART_0_Task), NULL);
    UART_0_Parse_TaskID = osThreadCreate(osThread (UART_0_Parse_Task), NULL);
CONSOL_SendString("Debug init! - [%u][%u][%u][%u]\r\n", UART_0_TaskID, UART_0_Parse_TaskID, actual_baudrate, Chip_Clock_GetMainClockRate());
    CONSOL_SendString("DLL - %u\r\n",LPC_USART0->DLL);
    CONSOL_SendString("DLM - %u\r\n",LPC_USART0->DLM);
    CONSOL_SendString("FDR - %u\r\n",LPC_USART0->FDR);

    return;
}

Outcomes