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 HELP............

I am using LPC 1114,with 12Mhz crystal frequency...

How can I get 9600 baud rate .....?

Please tell me how to use clock sources to get that baud rate?

Parents
  • I have checked user manual and using sample codes given by ARM.

    The following is my code , give me any suggestions ....

    /***************************************************************************************/
    
    
    #include "LPC11xx.h"
    
    #define IER_RBR         0x01
    #define IER_THRE        0x02
    #define IER_RLS         0x04
    
    #define LSR_RDR         0x01
    #define LSR_THRE        0x20
    
    void UARTInit(unsigned int Baudrate);
    void UARTSend(void);
    void UARTRecv(void);
    void delay(void);
    
    volatile unsigned char  RECV;
    
    
    int main (void)
    {
    
            UARTInit(9600);
    
            while (1)
            {
            UARTRecv();
            UARTSend();
            }
    }
    
    /*=========================================================================================*/
    void UARTInit(unsigned int baudrate)
    {
                    unsigned int regVal;
                    unsigned int Fdiv;
    
                    LPC_IOCON->PIO1_6 &= ~0x07;                      /*  UART I/O config */
                    LPC_IOCON->PIO1_6 |= 0x01;                           /* UART RXD */
                    LPC_IOCON->PIO1_7 &= ~0x07;
                    LPC_IOCON->PIO1_7 |= 0x01;                           /* UART TXD */
    
                    LPC_SYSCON->SYSPLLCTRL = (1<<3)|(1<<6);
                    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);  // UART CLK enable
                    LPC_SYSCON->UARTCLKDIV = 0x2;                /* divided by 1 */
    
                    LPC_UART->LCR = 0x83;                /* DLB=1, 8 bits, no Parity, 1 Stop bit */
                    regVal = LPC_SYSCON->UARTCLKDIV;
    
                    Fdiv = (((12000000/1)/regVal)/16)/baudrate ;    /*baud rate */
                    LPC_UART->DLM = Fdiv/256;
                    LPC_UART->DLL = Fdiv % 256;
                    LPC_UART->LCR = 0x03;        /* DLAB = 0 ,Disable access to divisor latches*/
                    LPC_UART->FCR = 0x07;        /* Enable and reset TX and RX FIFO. */
    
                    regVal = LPC_UART->LSR;      /* Read to clear the line status. */
    
                    return;
    }
    
    
    void UARTSend()
    {
            lcd_str("in snd");
            delay();
            LPC_UART->THR = RECV;        // for my testing i'm sending recd cahr+1 value
            while ( !(LPC_UART->LSR & 0x40) ); //wait until TEMT=0,i.e. U0THR contains valid data
    
    }
    
    void UARTRecv()
    {
            lcd_str("in recv");
            while(!(LPC_UART->LSR & (0x01)));
            RECV=LPC_UART->RBR;          //Store the char received in to a variable
    }
    
    
    /****************************************************************************************/
    

    with this code , I am getting simulation output. In simulation I'm getting baud rate other than 9600.

    I am using Xtal freq: 12Mhz

    Please help me......

Reply
  • I have checked user manual and using sample codes given by ARM.

    The following is my code , give me any suggestions ....

    /***************************************************************************************/
    
    
    #include "LPC11xx.h"
    
    #define IER_RBR         0x01
    #define IER_THRE        0x02
    #define IER_RLS         0x04
    
    #define LSR_RDR         0x01
    #define LSR_THRE        0x20
    
    void UARTInit(unsigned int Baudrate);
    void UARTSend(void);
    void UARTRecv(void);
    void delay(void);
    
    volatile unsigned char  RECV;
    
    
    int main (void)
    {
    
            UARTInit(9600);
    
            while (1)
            {
            UARTRecv();
            UARTSend();
            }
    }
    
    /*=========================================================================================*/
    void UARTInit(unsigned int baudrate)
    {
                    unsigned int regVal;
                    unsigned int Fdiv;
    
                    LPC_IOCON->PIO1_6 &= ~0x07;                      /*  UART I/O config */
                    LPC_IOCON->PIO1_6 |= 0x01;                           /* UART RXD */
                    LPC_IOCON->PIO1_7 &= ~0x07;
                    LPC_IOCON->PIO1_7 |= 0x01;                           /* UART TXD */
    
                    LPC_SYSCON->SYSPLLCTRL = (1<<3)|(1<<6);
                    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);  // UART CLK enable
                    LPC_SYSCON->UARTCLKDIV = 0x2;                /* divided by 1 */
    
                    LPC_UART->LCR = 0x83;                /* DLB=1, 8 bits, no Parity, 1 Stop bit */
                    regVal = LPC_SYSCON->UARTCLKDIV;
    
                    Fdiv = (((12000000/1)/regVal)/16)/baudrate ;    /*baud rate */
                    LPC_UART->DLM = Fdiv/256;
                    LPC_UART->DLL = Fdiv % 256;
                    LPC_UART->LCR = 0x03;        /* DLAB = 0 ,Disable access to divisor latches*/
                    LPC_UART->FCR = 0x07;        /* Enable and reset TX and RX FIFO. */
    
                    regVal = LPC_UART->LSR;      /* Read to clear the line status. */
    
                    return;
    }
    
    
    void UARTSend()
    {
            lcd_str("in snd");
            delay();
            LPC_UART->THR = RECV;        // for my testing i'm sending recd cahr+1 value
            while ( !(LPC_UART->LSR & 0x40) ); //wait until TEMT=0,i.e. U0THR contains valid data
    
    }
    
    void UARTRecv()
    {
            lcd_str("in recv");
            while(!(LPC_UART->LSR & (0x01)));
            RECV=LPC_UART->RBR;          //Store the char received in to a variable
    }
    
    
    /****************************************************************************************/
    

    with this code , I am getting simulation output. In simulation I'm getting baud rate other than 9600.

    I am using Xtal freq: 12Mhz

    Please help me......

Children