我正在使用UART of lPC1788
,因为我对PCLK as 12MHZ
进行了以下设置,并且波特率为115200,但在我模拟此代码时,波特率未指定为115200或约。< / p>
uint32_t uart0_init()
{
LPC_SC->PCONP |=(1<<3); //Enabling power/clock for UART0
LPC_IOCON->P0_2 = 1; //Selecting fn. 001 for P0.2(U0_TXD)
LPC_IOCON->P0_3 = 1; //Selecting fn. 001 for P0.3(U0_RXD)
LPC_UART0->LCR =(0x83); //Selecting DLAB=1,1 stop bit,Parity bit and 8-bit character length
LPC_UART0->DLL = 0x04; //For PCLK=12MHZ and baud rate as 115200,DLL=4(in dec.)
LPC_UART0->DLM = 0x00; //For PCLK=12MHZ and baud rate as 115200,DLM=0(in dec.)
LPC_UART0->FDR =(0x85); //DIVADDVAL=1(3:0) and MULVAL=2(7:4) in FDR calculated from the FRest value
LPC_UART0->LCR =(0x03); //Disabling DLAB=0
LPC_UART0->FCR |=(7<<0); //Enable FIFOEN,TXFIFORES and RXFIFORES in FCR(0,1,2)
LPC_UART0->FCR |=(0<<0); //Disable FIFOEN,TXFIFORES and RXFIFORES in FCR(0,1,2)
//NVIC_EnableIRQ(UART0_IRQn);
//LPC_UART0->IER = IER_RBRIE | IER_THREIE | IER_RXIE;
return 1;
}
对于我来说它接近384615,它完全不同。是否有任何计算要完全获得115200波特。
请为我做好准备..
答案 0 :(得分:0)
不要使用uart init来更改系统控制设置。如果你不小心,你会在别处覆盖它们。创建sysInit函数并将其设置在那里。将分频器设置为10(0x0a)。
LPC_SC->PCLKSEL = 0x0A;
这会将MCLK
除以10,您将获得12Mhz的外设时钟。之后,您需要设置FDR
和DLL
设置以达到~115200波特。