This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Baud rate setting for UART in LPC1788

I started work with UART of lPC1788,in that I did the following settings for PCLK as 12MHZ and baud rate as 115200
but while i am simulating this code the baud rate is not assigned as 115200 or approx.

uint32_t uart0_init()
{

LPC_SC->PCONP |=(1<<3); //Enabling power/clock for UART0

LPC_SC->PCLKSEL |=(1<<0); //Selecting PCLKDIV value as 1 for PCLKSEL

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;

}

For me its coming near 384615,its totally different.Is there any calculations to be done to obtain exact of 115200 baud.

Please do clear for me..

Thanks in advance for suggesting experts..

Parents Reply Children
  • To the OP:

    I tested your code on my environment.

    I guess that,
    1. your CCLK is 120MHz.
    2. you already have a PCLKDIV = 0x02. (by startup or system_lpc)
    3. by the below line, you get actually PCLKDIV = 0x03.

    LPC_SC->PCLKSEL |=(1<<0); //Selecting PCLKDIV value as 1 for PCLKSEL
    


    4. after your uart0_init(), you get baudrate = 384615.

  • Hi Mr.Jona,

    I checked for baud rate of 9600 with same setting except changing value for DLL and DLM value and FDR values.

    But even for 9600 also the value of baud is exceeding the 9600.

    Thanks a lot in advance.

  • Hi John,

    I am now clear with the points 2 and 3,but where I have to find the CCLK is 120MHz and to check for alteration of 12MHZ.

    Thanks a lot in advance.

  • > where I have to find the CCLK is 120MHz and to check for alteration of 12MHZ. <

    Not sure how you configure your project.

    In general, CCLK of LPC1788 is initially 12MHz.
    After the

    void SystemInit (void)
    


    in system_LPC177x_8x.c

      LPC_SC->CCLKSEL   = CCLKSEL_Val;      /* Setup Clock Divider                */
      LPC_SC->USBCLKSEL = USBCLKSEL_Val;    /* Setup USB Clock Divider            */
      LPC_SC->EMCCLKSEL = EMCCLKSEL_Val;    /* EMC Clock Selection                */
      LPC_SC->PCLKSEL   = PCLKSEL_Val;      /* Peripheral Clock Selection         */
      LPC_SC->PCONP     = PCONP_Val;        /* Power Control for Peripherals      */
      LPC_SC->CLKOUTCFG = CLKOUTCFG_Val;    /* Clock Output Configuration         */
    


    CCLK of LPC1788 is configured to 120MHz.

  • With the CCLK value of 120MHZ,I used to select the PCLKSEL value of 0x0000000A to obtain the PCLK of 12MHZ.Now I am getting PCLK of 12MHZ which is my required frequency and I am obtaining 9600 approx. value while debugging the code with UART0.

    Is this is a correct method to set 9600 baud rate?.

  • Why not used the CMSIS library code?
    It has routines, which when called (with correct parameter passing) will work as desired. It saves a lot of your time.

  • Hi D.7, Ya used the CMSIS library code,even in CMSIS they used PCLKSEL value as 0x00000002.But I want PCLK as 12Mhz and baud rate of 9600 to send a data to PC like devices.

    With that PCLKSEL value I am getting PCLK of 60MHZ,so what I asked.