SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By Athul
#198990
I've been trying to configure UART module of LPC1768. Board comes with a crystal oscillator of 12Mhz. It does nothing more than receiving a character and transmitting it at the same time. I am using Keil simulator.
This is the code,
Code: Select all
#include <LPC17xx.H>

void uart_init()
{
    LPC_PINCON->PINSEL0 = 0X0500000;
    LPC_UART2->LCR = 0X83;
    LPC_UART2->DLL = 162;
    LPC_UART2->LCR = 0X03;
}

int main()
{
    uart_init();

    while(1)
    {
        while(LPC_UART2->LSR & (1<<0));
        LPC_UART2->THR = LPC_UART2->RBR;
        while(LPC_UART2->LSR & (1<<6));
    }
}
I'm not configuring any PLL register, only using default values.

I"ve referred several forums to find the baud rate, https://www.google.co.in/search?q=lp176 ... e&ie=UTF-8

By referring system_LPC17xx.c,
Code: Select all
#define CLOCK_SETUP           1
#define SCS_Val               0x00000020
#define CLKSRCSEL_Val         0x00000001
#define PLL0_SETUP            1
#define PLL0CFG_Val           0x00050063
#define PLL1_SETUP            1
#define PLL1CFG_Val           0x00000023
#define CCLKCFG_Val           0x00000003
#define USBCLKCFG_Val         0x00000000
#define PCLKSEL0_Val          0x00000000
#define PCLKSEL1_Val          0x00000000
#define PCONP_Val             0x042887DE
#define CLKOUTCFG_Val         0x00000000
From #define PLL0CFG_Val 0x00050063,

Bit 14-0 supplies the M value, and the value stored here is M-1; 0x0063 which is 99 in decimal, So M = 100,

Bit 23-16 Supplies the value "N", The value stored here is N - 1; 0x05=5 in decimal, so N = 6

From #define CCLKCFG_Val 0x00000003,

Bit 7-0, Selects the divide value for creating the CPU clock (CCLK), By putting a value of 3, CCLK = PLLCLK/4

I'm using UART2, which comes under PCLKSEL2,

From #define PCLKSEL2_Val 0x00000000,

when set 0, PCLK_peripheral = CCLK/4

TO find PLL0 freq, PLL0_clk = (2 * M * FOSC) / N ==>PLL0_clk = (2 * 100 * 12)/6 ==>PLL0_clk = 400Mhz

Now, CCLK = PPL0_clk/4 ==>CCLK = 400 / 4 = 100Mhz

and PCLK = CCLK/4 = 100/4 = 25Mhz

To calculate DLL, DLL = PCLK/(16 * Baud rate) for 9600 Bpm, DLL = 25000000/(16 * 9600) ==>DLL = 162

But I can't transmit or receive anything when I tried to simulate the program I've only limited knowledge in ARM, that's why I wrote my calculation method so that anyone can correct me if I'm wrong.??

Did I make any mistakes in cofiguring UART or PCLK??
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]