void InitUART(void)
{
uint32_t ret_value;
UART_CONFIG_T cfg;
// First set the needed mux for TX and RX
Init_UART0_PinMux();
// Initialize UART0
Chip_UART_Init(LPC_USART0);
// UART clsock
Chip_Clock_SetUARTFRGDivider(1);
// 9600BPS, 8N1, ASYNC mode, no errors, clock filled in later
cfg.sys_clk_in_hz = 0; // U_PCLK frequency in Hz
cfg.baudrate_in_hz = 9600;// Baud Rate in Hz
cfg.config = 1;// 8N1
cfg.sync_mod = 0; // Asynchronous Mode
cfg.error_en = NO_ERR_EN;// Enable No Errors
// Perform a sanity check on the storage allocation
if (LPC_UARTD_API->uart_get_mem_size() > sizeof(uartHandleMEM))
{
// Example only: this should never happen and probably isn't needed for most UART code.
errorUART();
}
// Setup the UART handle
uartHandle = LPC_UARTD_API->uart_setup((uint32_t) LPC_USART0, (uint8_t *) &uartHandleMEM);
if (uartHandle == NULL)
{
errorUART();
}
// Need to tell UART ROM API function the current UART peripheral clock speed
cfg.sys_clk_in_hz = Chip_Clock_GetSystemClockRate();
// Initialize the UART with the configuration parameters
ret_value = LPC_UARTD_API->uart_init(uartHandle, &cfg);
LPC_SYSCTL->FRGCTRL = ret_value;
// Enable IRQ
NVIC_EnableIRQ(UART0_IRQn);
// Ready to TX
gotTXCallback = true;
} |