Reply by jhhey121282 April 25, 20082008-04-25
Hey Guys, Thank you for all your help. fortunately last night at
around 4:30 am (i guess this morning) we got it to fully function with
help from one of my friends and we finally got it working with the
liblpc2000.h library :) I'll include the code for other people just in
case :)

once again thank you,
Hiva

/**************************Code****************************/
#include

void UART0Initialize(unsigned long baudrate)
{
/* Configure UART */
unsigned int divisor liblpc2000_get_pclk(liblpc2000_get_cclk(OSCILLATOR_CLOCK_FREQUENCY)) /
(16 * baudrate);
U0LCR = 0x83; /* 8 bit, 1 stop bit, no parity, enable DLAB */
U0DLL = divisor & 0xFF;
U0DLM = (divisor >> 8) & 0xFF;
U0LCR &= ~0x80; /* Disable DLAB */
PINSEL0 = PINSEL0 & (~0xF)| 0x5;
U0FCR = 1;
}
--- In l..., wrote:
>
> Hello Hiva,
>
> Not sure how much of this is going to help, but you could try the
example
> code from RapidiTTy Lite which is free
> (http://www.tte-systems.com/download_list.php).
>
> There is a UART1 example there that does not require interrupts and
works on
> the LPC-P2129 from Olimex. Changing it to UART0 to support the 2138
*should*
> be straightforward.
>
> Dev
>
> _____
>
> From: l... [mailto:l...] On
Behalf Of
> mehiegl
> Sent: 25 April 2008 10:16
> To: l...
> Subject: [lpc2000] Re: Senior Project Help With the UART0
>
> What do you expect to see, and what are you seeing? You may have the
> correct baud rate, but have other problems in your code that is using
> the UART.
>
> Mark
>
> --- In lpc2000@yahoogroups .com,
> "jhhey121282" wrote:
> >
> > Hey Mark, Thanks for a quick response :)
> > i changed the VPBDIV to 0x04 as you said. although ever sooo close
> to
> > the output as i am getting mostly alphabits it is still off and not
> > transmitting the correct character. Thank you soooo much for your
> help
> > as i am just getting into the arm world and this project is due
> > tomorrow with only the uart left to finish :)
> >
> > Thank you soooo much
> > Hiva
> >
> > --- In lpc2000@yahoogroups .com,
> "mehiegl" wrote:
> > >
> > > With a PLL multiplier of 4, your CCLK is 58982400. Since your
> VPBDIV
> > > is 1, your PCLK is 58982400 too. Your divisor won't work for 9600
> > > baud. It's off by afactor of 4.
> > >
> > > Mark
>
>
>
>

An Engineer's Guide to the LPC2100 Series

Reply by tech...@tte-systems.com April 25, 20082008-04-25
Hello Hiva,

Not sure how much of this is going to help, but you could try the example
code from RapidiTTy Lite which is free
(http://www.tte-systems.com/download_list.php).

There is a UART1 example there that does not require interrupts and works on
the LPC-P2129 from Olimex. Changing it to UART0 to support the 2138 *should*
be straightforward.

Dev

_____

From: l... [mailto:l...] On Behalf Of
mehiegl
Sent: 25 April 2008 10:16
To: l...
Subject: [lpc2000] Re: Senior Project Help With the UART0

What do you expect to see, and what are you seeing? You may have the
correct baud rate, but have other problems in your code that is using
the UART.

Mark

--- In lpc2000@yahoogroups .com,
"jhhey121282" wrote:
>
> Hey Mark, Thanks for a quick response :)
> i changed the VPBDIV to 0x04 as you said. although ever sooo close
to
> the output as i am getting mostly alphabits it is still off and not
> transmitting the correct character. Thank you soooo much for your
help
> as i am just getting into the arm world and this project is due
> tomorrow with only the uart left to finish :)
>
> Thank you soooo much
> Hiva
>
> --- In lpc2000@yahoogroups .com,
"mehiegl" wrote:
> >
> > With a PLL multiplier of 4, your CCLK is 58982400. Since your
VPBDIV
> > is 1, your PCLK is 58982400 too. Your divisor won't work for 9600
> > baud. It's off by afactor of 4.
> >
> > Mark


Reply by mehiegl April 25, 20082008-04-25
What do you expect to see, and what are you seeing? You may have the
correct baud rate, but have other problems in your code that is using
the UART.

Mark

--- In l..., "jhhey121282" wrote:
>
> Hey Mark, Thanks for a quick response :)
> i changed the VPBDIV to 0x04 as you said. although ever sooo close
to
> the output as i am getting mostly alphabits it is still off and not
> transmitting the correct character. Thank you soooo much for your
help
> as i am just getting into the arm world and this project is due
> tomorrow with only the uart left to finish :)
>
> Thank you soooo much
> Hiva
>
> --- In l..., "mehiegl" wrote:
> >
> > With a PLL multiplier of 4, your CCLK is 58982400. Since your
VPBDIV
> > is 1, your PCLK is 58982400 too. Your divisor won't work for 9600
> > baud. It's off by afactor of 4.
> >
> > Mark

Reply by grahamg227 April 25, 20082008-04-25
Look in the file section of this forum, I am sure there is a utility
called BAUDCALC.exe which will help confirm your calcs. Or just Google
it here is one link http://www.roboticsforyou.com/?m 0709
Reply by mjames_doveridge April 25, 20082008-04-25
--- In l..., "jhhey121282" wrote:
>
> Hey Mark, Thanks for a quick response :)
> i changed the VPBDIV to 0x04 as you said. although ever sooo close to
> the output as i am getting mostly alphabits it is still off and not
> transmitting the correct character. Thank you soooo much for your help
> as i am just getting into the arm world and this project is due
> tomorrow with only the uart left to finish :)
>
> Thank you soooo much
> Hiva
>

If you have to deliver now, this is not the time for understanding.
Either change the values until it works, (add 5%, does it get better
or worse - if worse, take off 10% and so on..), or send some $AA's and
use a scope to determine exactly how far off you are in bit timing and
then calculate the value for the divisor to give the desired baud rate.

When I first connected up my CAN bus, I was able to communicate fine
between the two CAN ports on my development board but got no comms in
either direction with the other nodes on the bus. I looked for a while
at the calculations, but then resorted to a scope. It was immediately
obvious that I was sending/receiving at twice the rate I thought I
was. A minute later, after an edit/rebuild, I had good comms.

Sometimes, you just have to accept what is, especially if customers
are breathing down your neck. Just force it to work!

Once your serial comms is working, you can go back and more easily
find the error in your calculation of the initial values.

Rgds,
Martin

Reply by jhhey121282 April 24, 20082008-04-24
Any other Ideas as to why im getting the wrong values?

i would appreciate any help
Thanks,
Hiva
--- In l..., "jhhey121282" wrote:
>
> Hey Mark, Thanks for a quick response :)
> i changed the VPBDIV to 0x04 as you said. although ever sooo close to
> the output as i am getting mostly alphabits it is still off and not
> transmitting the correct character. Thank you soooo much for your help
> as i am just getting into the arm world and this project is due
> tomorrow with only the uart left to finish :)
>
> Thank you soooo much
> Hiva
>
> --- In l..., "mehiegl" wrote:
> >
> > With a PLL multiplier of 4, your CCLK is 58982400. Since your VPBDIV
> > is 1, your PCLK is 58982400 too. Your divisor won't work for 9600
> > baud. It's off by afactor of 4.
> >
> > Mark
> > --- In l..., "jhhey121282" wrote:
> > >
> > > Hi guys, Im using an olimex 2138 header board and am trying to use
> > the
> > > UART0 to transmit across a set of Xbees. the transmission is working
> > > as far as we know but i get a bunch of junk on the other side.now i
> > am
> > > thinking that i am not setting the baud rate correctly but i don't
> > > know. i have tried connecting directly to the serial port and still
> > > getting the same junk. below i will include a copy of my code, can
> > you
> > > guys please advise. also this board has a 14.74560 MHz oscillator on
> > > it. can you guys please advise?
> > >
> > > Thanks,
> > > Hiva
> > >
> > >
> > > /************************************Code***************************
> > ***/
> > > #include
> > >
> > > #define TX_BUFSIZE 80
> > > static unsigned char txbuf[TX_BUFSIZE];
> > > static unsigned char txptr = 0;
> > > static unsigned char typtr = 0;
> > > //void UART1_Init(void)
> > > //{
> > > //VPBDIV = 0x01;
> > > //// Fpclk = 12.000.000 MHz
> > > //// DLM,DLH = Fpclk / (19200*16) = 39 = 0x27
> > > //PINSEL0 |= 0x00000005; // Select UART1 RXD/TXD
> > > //U0FCR = 0x07; // Enable and clear FIFO's
> > > //U0LCR = 0x83; // 8N1, enable Divisor latch bit
> > > //U0DLL = 0x60; // baud rate fixed to 19200 @ PCLK = 12 Mhz
> > > //U0DLM = 0x00;
> > > //U0LCR = 0x03; // Disable Divisor latch bit
> > > //}
> > >
> > >
> > > void UART0_Init(void)
> > > {
> > > unsigned char tmp;
> > > PINSEL0 |= 0x00000005;
> > >
> > > VPBDIV = 0x01; /* VPB bus clock is the same as the processor
> > > clock. */
> > >
> > >
> > > U0IER = 0x00; /* disable all interrups of port */
> > > tmp = U0IIR; /* clear interrupt id */
> > > tmp = U0RBR; /* clear receive reg. (to reset possibly intr) */
> > > tmp = U0LSR; /* clear linestatus (to reset possibly intr) */
> > > tmp = U0MSR; /* clear modemstatus (to reset possibly intr) */
> > >
> > > U0LCR = 0x80; /* select divisor latches */
> > > U0DLL = 0x60; /* set for 9600 Baud */
> > > U0DLM = 0x00; /* set for 9600 Baud */
> > > U0LCR = 0x03; /* 8 bit character length, 1 stop bit, Disable
> > parity
> > > generation and checking, Disable break transmission */
> > >
> > > } /* end Hw_Init_UART0 */
> > >
> > >
> > >
> > >
> > >
> > >
> > > static void SendString(char *text)
> > > {
> > > if (txptr == 0) // previous message send ?
> > > {
> > > typtr = 0;
> > > while(*text)
> > > {
> > > txbuf[txptr++] = *text++;
> > > if(txptr >= TX_BUFSIZE)
> > > txptr = 0;
> > > }
> > > }
> > > }
> > > static void UART0_Tx_Int(void) // Called from the main loop
> > > {
> > > char i = 16;
> > > if (U0LCR && 0x20) // transmit FIFO empty ?
> > > {
> > > while (i && txptr)
> > > {
> > > U0THR = txbuf[typtr++];
> > > txptr --;
> > > i --;
> > > }
> > > }
> > > }
> > >
> > > void Initialize(void)
> > > {
> > >
> > >
> > > // Setting the Phased Lock Loop (PLL)
> > > // ----------------------------------
> > > //
> > > // Olimex LPC-P2138 has a 14.7456 mhz crystal
> > > //
> > > // We'd like the LPC2138 to run at 53.2368 mhz (has to be an
> > > even multiple of crystal)
> > > //
> > > // According to the Philips LPC2106 manual: M = cclk / Fosc
> > > where: M = PLL multiplier (bits 0-4 of PLLCFG)
> > > // cclk = 53236800 hz
> > > // Fosc = 14745600 hz
> > > //
> > > // Solving: M = 53236800 / 14745600 = 3.6103515625
> > > // M = 4 (round up)
> > > //
> > > // Note: M - 1 must be entered into bits 0-4 of PLLCFG
> > (assign 3
> > > to these bits)
> > > //
> > > //
> > > // The Current Controlled Oscilator (CCO) must operate in the
> > > range 156 mhz to 320 mhz
> > > //
> > > // According to the Philips LPC2106 manual: Fcco = cclk * 2 *
> > P
> > > where: Fcco = CCO frequency
> > > // cclk = 53236800 hz
> > > // P = PLL divisor (bits 5-6 of PLLCFG)
> > > //
> > > // Solving: Fcco = 53236800 * 2 * P
> > > // P = 2 (trial value)
> > > // Fcco = 53236800 * 2 * 2
> > > // Fcc0 = 212947200 hz (good choice for P since it's within
> > the
> > > 156 mhz to 320 mhz range
> > > //
> > > // From Table 19 (page 4Cool of Philips LPC2106 manual P = 2,
> > > PLLCFG bits 5-6 = 1 (assign 1 to these bits)
> > > //
> > > // Finally: PLLCFG = 0 01 00011 = 0x23
> > > //
> > > // Final note: to load PLLCFG register, we must use the 0xAA
> > > followed 0x55 write sequence to the PLLFEED register
> > > // this is done in the short function feed() below
> > > //
> > >
> > > // Setting Multiplier and Divider values
> > > PLLCFG=0x23;
> > > feed();
> > >
> > > // Enabling the PLL */
> > > PLLCON=0x1;
> > > feed();
> > >
> > > // Wait for the PLL to lock to set frequency
> > > while(!(PLLSTAT & 0x400)) ;
> > >
> > > // Connect the PLL as the clock source
> > > PLLCON=0x3;
> > > feed();
> > >
> > > // Enabling MAM and setting number of clocks used for Flash
> > > memory fetch (4 cclks in this case)
> > > MAMCR=0x2;
> > > MAMTIM=0x4;
> > >
> > > }
> > > void feed(void)
> > > {
> > > PLLFEED=0xAA;
> > > PLLFEED=0x55;
> > > }
> > >
> > >
> > > int main (void)
> > > {
> > > UART0_Init();
> > > while (1)
> > > {
> > > SendString("A\n\r");
> > > UART0_Tx_Int();
> > >
> > > }
> > > }
> > >
>
Reply by jhhey121282 April 24, 20082008-04-24
Hey Mark, Thanks for a quick response :)
i changed the VPBDIV to 0x04 as you said. although ever sooo close to
the output as i am getting mostly alphabits it is still off and not
transmitting the correct character. Thank you soooo much for your help
as i am just getting into the arm world and this project is due
tomorrow with only the uart left to finish :)

Thank you soooo much
Hiva

--- In l..., "mehiegl" wrote:
>
> With a PLL multiplier of 4, your CCLK is 58982400. Since your VPBDIV
> is 1, your PCLK is 58982400 too. Your divisor won't work for 9600
> baud. It's off by afactor of 4.
>
> Mark
> --- In l..., "jhhey121282" wrote:
> >
> > Hi guys, Im using an olimex 2138 header board and am trying to use
> the
> > UART0 to transmit across a set of Xbees. the transmission is working
> > as far as we know but i get a bunch of junk on the other side.now i
> am
> > thinking that i am not setting the baud rate correctly but i don't
> > know. i have tried connecting directly to the serial port and still
> > getting the same junk. below i will include a copy of my code, can
> you
> > guys please advise. also this board has a 14.74560 MHz oscillator on
> > it. can you guys please advise?
> >
> > Thanks,
> > Hiva
> >
> >
> > /************************************Code***************************
> ***/
> > #include
> >
> > #define TX_BUFSIZE 80
> > static unsigned char txbuf[TX_BUFSIZE];
> > static unsigned char txptr = 0;
> > static unsigned char typtr = 0;
> > //void UART1_Init(void)
> > //{
> > //VPBDIV = 0x01;
> > //// Fpclk = 12.000.000 MHz
> > //// DLM,DLH = Fpclk / (19200*16) = 39 = 0x27
> > //PINSEL0 |= 0x00000005; // Select UART1 RXD/TXD
> > //U0FCR = 0x07; // Enable and clear FIFO's
> > //U0LCR = 0x83; // 8N1, enable Divisor latch bit
> > //U0DLL = 0x60; // baud rate fixed to 19200 @ PCLK = 12 Mhz
> > //U0DLM = 0x00;
> > //U0LCR = 0x03; // Disable Divisor latch bit
> > //}
> >
> >
> > void UART0_Init(void)
> > {
> > unsigned char tmp;
> > PINSEL0 |= 0x00000005;
> >
> > VPBDIV = 0x01; /* VPB bus clock is the same as the processor
> > clock. */
> >
> >
> > U0IER = 0x00; /* disable all interrups of port */
> > tmp = U0IIR; /* clear interrupt id */
> > tmp = U0RBR; /* clear receive reg. (to reset possibly intr) */
> > tmp = U0LSR; /* clear linestatus (to reset possibly intr) */
> > tmp = U0MSR; /* clear modemstatus (to reset possibly intr) */
> >
> > U0LCR = 0x80; /* select divisor latches */
> > U0DLL = 0x60; /* set for 9600 Baud */
> > U0DLM = 0x00; /* set for 9600 Baud */
> > U0LCR = 0x03; /* 8 bit character length, 1 stop bit, Disable
> parity
> > generation and checking, Disable break transmission */
> >
> > } /* end Hw_Init_UART0 */
> >
> >
> >
> >
> >
> >
> > static void SendString(char *text)
> > {
> > if (txptr == 0) // previous message send ?
> > {
> > typtr = 0;
> > while(*text)
> > {
> > txbuf[txptr++] = *text++;
> > if(txptr >= TX_BUFSIZE)
> > txptr = 0;
> > }
> > }
> > }
> > static void UART0_Tx_Int(void) // Called from the main loop
> > {
> > char i = 16;
> > if (U0LCR && 0x20) // transmit FIFO empty ?
> > {
> > while (i && txptr)
> > {
> > U0THR = txbuf[typtr++];
> > txptr --;
> > i --;
> > }
> > }
> > }
> >
> > void Initialize(void)
> > {
> >
> >
> > // Setting the Phased Lock Loop (PLL)
> > // ----------------------------------
> > //
> > // Olimex LPC-P2138 has a 14.7456 mhz crystal
> > //
> > // We'd like the LPC2138 to run at 53.2368 mhz (has to be an
> > even multiple of crystal)
> > //
> > // According to the Philips LPC2106 manual: M = cclk / Fosc
> > where: M = PLL multiplier (bits 0-4 of PLLCFG)
> > // cclk = 53236800 hz
> > // Fosc = 14745600 hz
> > //
> > // Solving: M = 53236800 / 14745600 = 3.6103515625
> > // M = 4 (round up)
> > //
> > // Note: M - 1 must be entered into bits 0-4 of PLLCFG
> (assign 3
> > to these bits)
> > //
> > //
> > // The Current Controlled Oscilator (CCO) must operate in the
> > range 156 mhz to 320 mhz
> > //
> > // According to the Philips LPC2106 manual: Fcco = cclk * 2 *
> P
> > where: Fcco = CCO frequency
> > // cclk = 53236800 hz
> > // P = PLL divisor (bits 5-6 of PLLCFG)
> > //
> > // Solving: Fcco = 53236800 * 2 * P
> > // P = 2 (trial value)
> > // Fcco = 53236800 * 2 * 2
> > // Fcc0 = 212947200 hz (good choice for P since it's within
> the
> > 156 mhz to 320 mhz range
> > //
> > // From Table 19 (page 4Cool of Philips LPC2106 manual P = 2,
> > PLLCFG bits 5-6 = 1 (assign 1 to these bits)
> > //
> > // Finally: PLLCFG = 0 01 00011 = 0x23
> > //
> > // Final note: to load PLLCFG register, we must use the 0xAA
> > followed 0x55 write sequence to the PLLFEED register
> > // this is done in the short function feed() below
> > //
> >
> > // Setting Multiplier and Divider values
> > PLLCFG=0x23;
> > feed();
> >
> > // Enabling the PLL */
> > PLLCON=0x1;
> > feed();
> >
> > // Wait for the PLL to lock to set frequency
> > while(!(PLLSTAT & 0x400)) ;
> >
> > // Connect the PLL as the clock source
> > PLLCON=0x3;
> > feed();
> >
> > // Enabling MAM and setting number of clocks used for Flash
> > memory fetch (4 cclks in this case)
> > MAMCR=0x2;
> > MAMTIM=0x4;
> >
> > }
> > void feed(void)
> > {
> > PLLFEED=0xAA;
> > PLLFEED=0x55;
> > }
> >
> >
> > int main (void)
> > {
> > UART0_Init();
> > while (1)
> > {
> > SendString("A\n\r");
> > UART0_Tx_Int();
> >
> > }
> > }
>

Reply by mehiegl April 24, 20082008-04-24
With a PLL multiplier of 4, your CCLK is 58982400. Since your VPBDIV
is 1, your PCLK is 58982400 too. Your divisor won't work for 9600
baud. It's off by afactor of 4.

Mark
--- In l..., "jhhey121282" wrote:
>
> Hi guys, Im using an olimex 2138 header board and am trying to use
the
> UART0 to transmit across a set of Xbees. the transmission is working
> as far as we know but i get a bunch of junk on the other side.now i
am
> thinking that i am not setting the baud rate correctly but i don't
> know. i have tried connecting directly to the serial port and still
> getting the same junk. below i will include a copy of my code, can
you
> guys please advise. also this board has a 14.74560 MHz oscillator on
> it. can you guys please advise?
>
> Thanks,
> Hiva
> /************************************Code***************************
***/
> #include #define TX_BUFSIZE 80
> static unsigned char txbuf[TX_BUFSIZE];
> static unsigned char txptr = 0;
> static unsigned char typtr = 0;
> //void UART1_Init(void)
> //{
> //VPBDIV = 0x01;
> //// Fpclk = 12.000.000 MHz
> //// DLM,DLH = Fpclk / (19200*16) = 39 = 0x27
> //PINSEL0 |= 0x00000005; // Select UART1 RXD/TXD
> //U0FCR = 0x07; // Enable and clear FIFO's
> //U0LCR = 0x83; // 8N1, enable Divisor latch bit
> //U0DLL = 0x60; // baud rate fixed to 19200 @ PCLK = 12 Mhz
> //U0DLM = 0x00;
> //U0LCR = 0x03; // Disable Divisor latch bit
> //}
> void UART0_Init(void)
> {
> unsigned char tmp;
> PINSEL0 |= 0x00000005;
>
> VPBDIV = 0x01; /* VPB bus clock is the same as the processor
> clock. */
> U0IER = 0x00; /* disable all interrups of port */
> tmp = U0IIR; /* clear interrupt id */
> tmp = U0RBR; /* clear receive reg. (to reset possibly intr) */
> tmp = U0LSR; /* clear linestatus (to reset possibly intr) */
> tmp = U0MSR; /* clear modemstatus (to reset possibly intr) */
>
> U0LCR = 0x80; /* select divisor latches */
> U0DLL = 0x60; /* set for 9600 Baud */
> U0DLM = 0x00; /* set for 9600 Baud */
> U0LCR = 0x03; /* 8 bit character length, 1 stop bit, Disable
parity
> generation and checking, Disable break transmission */
>
> } /* end Hw_Init_UART0 */
> static void SendString(char *text)
> {
> if (txptr == 0) // previous message send ?
> {
> typtr = 0;
> while(*text)
> {
> txbuf[txptr++] = *text++;
> if(txptr >= TX_BUFSIZE)
> txptr = 0;
> }
> }
> }
> static void UART0_Tx_Int(void) // Called from the main loop
> {
> char i = 16;
> if (U0LCR && 0x20) // transmit FIFO empty ?
> {
> while (i && txptr)
> {
> U0THR = txbuf[typtr++];
> txptr --;
> i --;
> }
> }
> }
>
> void Initialize(void)
> {
>
>
> // Setting the Phased Lock Loop (PLL)
> // ----------------------------------
> //
> // Olimex LPC-P2138 has a 14.7456 mhz crystal
> //
> // We'd like the LPC2138 to run at 53.2368 mhz (has to be an
> even multiple of crystal)
> //
> // According to the Philips LPC2106 manual: M = cclk / Fosc
> where: M = PLL multiplier (bits 0-4 of PLLCFG)
> // cclk = 53236800 hz
> // Fosc = 14745600 hz
> //
> // Solving: M = 53236800 / 14745600 = 3.6103515625
> // M = 4 (round up)
> //
> // Note: M - 1 must be entered into bits 0-4 of PLLCFG
(assign 3
> to these bits)
> //
> //
> // The Current Controlled Oscilator (CCO) must operate in the
> range 156 mhz to 320 mhz
> //
> // According to the Philips LPC2106 manual: Fcco = cclk * 2 *
P
> where: Fcco = CCO frequency
> // cclk = 53236800 hz
> // P = PLL divisor (bits 5-6 of PLLCFG)
> //
> // Solving: Fcco = 53236800 * 2 * P
> // P = 2 (trial value)
> // Fcco = 53236800 * 2 * 2
> // Fcc0 = 212947200 hz (good choice for P since it's within
the
> 156 mhz to 320 mhz range
> //
> // From Table 19 (page 4Cool of Philips LPC2106 manual P = 2,
> PLLCFG bits 5-6 = 1 (assign 1 to these bits)
> //
> // Finally: PLLCFG = 0 01 00011 = 0x23
> //
> // Final note: to load PLLCFG register, we must use the 0xAA
> followed 0x55 write sequence to the PLLFEED register
> // this is done in the short function feed() below
> //
>
> // Setting Multiplier and Divider values
> PLLCFG=0x23;
> feed();
>
> // Enabling the PLL */
> PLLCON=0x1;
> feed();
>
> // Wait for the PLL to lock to set frequency
> while(!(PLLSTAT & 0x400)) ;
>
> // Connect the PLL as the clock source
> PLLCON=0x3;
> feed();
>
> // Enabling MAM and setting number of clocks used for Flash
> memory fetch (4 cclks in this case)
> MAMCR=0x2;
> MAMTIM=0x4;
>
> }
> void feed(void)
> {
> PLLFEED=0xAA;
> PLLFEED=0x55;
> }
> int main (void)
> {
> UART0_Init();
> while (1)
> {
> SendString("A\n\r");
> UART0_Tx_Int();
>
> }
> }
>

Reply by jhhey121282 April 24, 20082008-04-24
Hi guys, Im using an olimex 2138 header board and am trying to use the
UART0 to transmit across a set of Xbees. the transmission is working
as far as we know but i get a bunch of junk on the other side.now i am
thinking that i am not setting the baud rate correctly but i don't
know. i have tried connecting directly to the serial port and still
getting the same junk. below i will include a copy of my code, can you
guys please advise. also this board has a 14.74560 MHz oscillator on
it. can you guys please advise?

Thanks,
Hiva
/************************************Code******************************/
#include

#define TX_BUFSIZE 80
static unsigned char txbuf[TX_BUFSIZE];
static unsigned char txptr = 0;
static unsigned char typtr = 0;
//void UART1_Init(void)
//{
//VPBDIV = 0x01;
//// Fpclk = 12.000.000 MHz
//// DLM,DLH = Fpclk / (19200*16) = 39 = 0x27
//PINSEL0 |= 0x00000005; // Select UART1 RXD/TXD
//U0FCR = 0x07; // Enable and clear FIFO's
//U0LCR = 0x83; // 8N1, enable Divisor latch bit
//U0DLL = 0x60; // baud rate fixed to 19200 @ PCLK = 12 Mhz
//U0DLM = 0x00;
//U0LCR = 0x03; // Disable Divisor latch bit
//}
void UART0_Init(void)
{
unsigned char tmp;
PINSEL0 |= 0x00000005;

VPBDIV = 0x01; /* VPB bus clock is the same as the processor
clock. */
U0IER = 0x00; /* disable all interrups of port */
tmp = U0IIR; /* clear interrupt id */
tmp = U0RBR; /* clear receive reg. (to reset possibly intr) */
tmp = U0LSR; /* clear linestatus (to reset possibly intr) */
tmp = U0MSR; /* clear modemstatus (to reset possibly intr) */

U0LCR = 0x80; /* select divisor latches */
U0DLL = 0x60; /* set for 9600 Baud */
U0DLM = 0x00; /* set for 9600 Baud */
U0LCR = 0x03; /* 8 bit character length, 1 stop bit, Disable parity
generation and checking, Disable break transmission */

} /* end Hw_Init_UART0 */

static void SendString(char *text)
{
if (txptr == 0) // previous message send ?
{
typtr = 0;
while(*text)
{
txbuf[txptr++] = *text++;
if(txptr >= TX_BUFSIZE)
txptr = 0;
}
}
}
static void UART0_Tx_Int(void) // Called from the main loop
{
char i = 16;
if (U0LCR && 0x20) // transmit FIFO empty ?
{
while (i && txptr)
{
U0THR = txbuf[typtr++];
txptr --;
i --;
}
}
}

void Initialize(void)
{

// Setting the Phased Lock Loop (PLL)
// ----------------------------------
//
// Olimex LPC-P2138 has a 14.7456 mhz crystal
//
// We'd like the LPC2138 to run at 53.2368 mhz (has to be an
even multiple of crystal)
//
// According to the Philips LPC2106 manual: M = cclk / Fosc
where: M = PLL multiplier (bits 0-4 of PLLCFG)
// cclk = 53236800 hz
// Fosc = 14745600 hz
//
// Solving: M = 53236800 / 14745600 = 3.6103515625
// M = 4 (round up)
//
// Note: M - 1 must be entered into bits 0-4 of PLLCFG (assign 3
to these bits)
//
//
// The Current Controlled Oscilator (CCO) must operate in the
range 156 mhz to 320 mhz
//
// According to the Philips LPC2106 manual: Fcco = cclk * 2 * P
where: Fcco = CCO frequency
// cclk = 53236800 hz
// P = PLL divisor (bits 5-6 of PLLCFG)
//
// Solving: Fcco = 53236800 * 2 * P
// P = 2 (trial value)
// Fcco = 53236800 * 2 * 2
// Fcc0 = 212947200 hz (good choice for P since it's within the
156 mhz to 320 mhz range
//
// From Table 19 (page 4Cool of Philips LPC2106 manual P = 2,
PLLCFG bits 5-6 = 1 (assign 1 to these bits)
//
// Finally: PLLCFG = 0 01 00011 = 0x23
//
// Final note: to load PLLCFG register, we must use the 0xAA
followed 0x55 write sequence to the PLLFEED register
// this is done in the short function feed() below
//

// Setting Multiplier and Divider values
PLLCFG=0x23;
feed();

// Enabling the PLL */
PLLCON=0x1;
feed();

// Wait for the PLL to lock to set frequency
while(!(PLLSTAT & 0x400)) ;

// Connect the PLL as the clock source
PLLCON=0x3;
feed();

// Enabling MAM and setting number of clocks used for Flash
memory fetch (4 cclks in this case)
MAMCR=0x2;
MAMTIM=0x4;

}
void feed(void)
{
PLLFEED=0xAA;
PLLFEED=0x55;
}
int main (void)
{
UART0_Init();
while (1)
{
SendString("A\n\r");
UART0_Tx_Int();

}
}