Content originally posted in LPCWare by Efendi on Thu Jan 08 08:03:39 MST 2015
Hello ... I am using the following code to UART1_init but during the simulation the DLL and DLM registers don't keep its value in the end of code the DLL and DLM reset. Also I use __irq void UART1_IRQHandler(void) interrupt function but I can not get RX interrup to read the data.
void UART1_init(unsigned long baudrate)
{
// Var. Def.
uint32_t Fdiv;
NVIC_DisableIRQ(UART1_IRQn); // Disable all UART1 intrruptes for initialize
// UART ports configuration.
LPC_IOCON->PIO0_8 &= ~0x07; // UART1 I/O port2_12 config as UART1_RXD1
LPC_IOCON->PIO0_8 |= 0x03; // UART1 RXD LOC0.
LPC_IOCON->PIO0_9 &= ~0x07;// UART1 I/O port1_13 config as UART1_TXD1
LPC_IOCON->PIO0_9 |= 0x03; // UART1 TXD LOC0/.
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<13);
LPC_SYSCON->UART1CLKDIV = 0x1;
//Baudrate configuration.
LPC_UART1->LCR = 0x83; //8 bits, no Parity, 1 Stop bit, and DLAB=1 enable it for config PCLK.
Fdiv = (((SystemCoreClock*LPC_SYSCON->SYSAHBCLKDIV)/LPC_SYSCON->UART0CLKDIV)/16)/baudrate;
//Fdiv = ( UART1_PCLK / 16 ) / baudrate ;//baud rate.
LPC_UART1->DLM = Fdiv / 256; // Config the baudrate register of UART1.
LPC_UART1->DLL = Fdiv % 256;
//Data packet configuration.
LPC_UART1->LCR = 0x03; // DLAB = 0, for config RS232.
// RS232 Multidrop Mode configuration
LPC_UART1->FCR = 0x07; // Enable and reset TX and RX FIFO.
NVIC_EnableIRQ(UART1_IRQn); // Enable Nested Vector Interrupt Control (NVIC) of UART0.
LPC_UART1->IER = 0x07; // Enable RBR, THR and LSR
return;
}