else if ( PortNum == 3 ) { LPC_PINCON->PINSEL0 &= ~0x0000000F; LPC_PINCON->PINSEL0 |= 0x0000000A; /* RxD3 is P0.1 and TxD3 is P0.0 */ LPC_SC->PCONP |= 1<<4 | 1<<25; //Enable PCUART1 /* By default, the PCLKSELx value is zero, thus, the PCLK for all the peripherals is 1/4 of the SystemFrequency. */ /* Bit 6~7 is for UART3 */ pclkdiv = (LPC_SC->PCLKSEL1 >> 18) & 0x03; switch ( pclkdiv ) { case 0x00: default: pclk = SystemCoreClock/4; break; case 0x01: pclk = SystemCoreClock; break; case 0x02: pclk = SystemCoreClock/2; break; case 0x03: pclk = SystemCoreClock/8; break; } LPC_UART3->LCR = 0x83;/* 8 bits, no Parity, 1 Stop bit */ Fdiv = ( pclk / 16 ) / baudrate ;/*baud rate */ LPC_UART3->DLM = Fdiv / 256; LPC_UART3->DLL = Fdiv % 256; LPC_UART3->LCR = 0x03;/* DLAB = 0 */ LPC_UART3->FCR = 0x07;/* Enable and reset TX and RX FIFO. */ NVIC_EnableIRQ(UART3_IRQn); LPC_UART3->IER = IER_RBR | IER_THRE | IER_RLS;/* Enable UART3 interrupt */ } |
clock baudrate = ------- divisor freq * mulVal clock = ------------------------- 16 * (mulVal + divAddVal) divisor = DLM << 8 + DLL |
1 <= divAddVal <= 15 divAddVal < mulVal 2 <= mulVal <= 15 divisor > 2 |