Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LPC2148 async serial baud rate confusion

Status
Not open for further replies.

futz

Active Member
I'm using modified Philips AN10369 code to do async serial out on my LPC2148. But I'm a bit confused. Using the formula (and a baudrate calculator I found on the NXP site) to find U0DLL, I get a number that gets me approximately 93750 baud, instead of my desired 9600.

The formula is as follows:
Required baud rate= VPB clock/ (16 * Divisor value)

If I hadn't had my Saleae Logic (with autobaud feature - LOVE IT!!! :D) I'd never even get close. By trial and error changing the number, recompiling and grabbing data with Logic I quickly changed the number to the correct U0DLL=0xc3, which gives me 9615 baud. Works perfect.

What I don't understand is why this is. The PLL is not enabled. The chip runs on a 12MHz crystal. Default peripheral clock is 1/4 of system clock, so it should be 3MHz, right?

I'm missing something. Just not sure what yet... :confused:
EDIT: More calculating tells me I'm running PCLK at 30MHz, though I have no idea how that's even possible (yet) without the PLL being involved.

Ha! The probes just barely fit the pins on this 16-SOIC:
**broken link removed**

The code:
Code:
#include "LPC214x.h"
void init(void);
void delay_ms(int);

int main()
{
	int i;
	char c[]="Futz's LPC2148";
	init();

	while(1){
		i=0;
		while(c[i]){
			U0THR=c[i];
			i++;
		}
		U0THR=0x0a;
		U0THR=0x0d;
		while(!(U0LSR && 0x40));
		delay_ms(250);
	}
}	

void init()
{
	PINSEL0=0x05;
	U0FCR=0x07;		//enable and clear FIFOs
	U0LCR=0x83;		//8-N-1, enable divisors
	U0DLL=0xc3;		//9600 baud (9615)
	U0DLM=0x00;
	U0LCR=0x03;		//8-N-1, disable divisors
}

void delay_ms(int x)		//this isn't accurate right now
{				//it's just a rough delay
	int a,b;
	for(a=0;a<x;a++){
		for(b=0;b<3000;b++);
	}
}

The Logic's output for one line:
bleh.jpg
 
Last edited:
I think I've got it figured out. Seems that Crossworks' startup code diddles the clock speeds and other settings to what someone who wrote that code thought would be good.

In other words, the program doesn't start up in default chip settings as I had assumed. To get the PLL/MAM/VPBDIV, etc. settings you expect, you have to explicitly set them yourself. Otherwise you get what the startup code gives you, which is NOT defaults.
 
I think I've got it figured out. Seems that Crossworks' startup code diddles the clock speeds and other settings to what someone who wrote that code thought would be good.

In other words, the program doesn't start up in default chip settings as I had assumed. To get the PLL/MAM/VPBDIV, etc. settings you expect, you have to explicitly set them yourself. Otherwise you get what the startup code gives you, which is NOT defaults.
Good for you! :) Are you liking the ARMs?

Gotta love those guys, that sort of crap should be in bold in the manuals!

Dan
 
Good for you! :) Are you liking the ARMs?
Yes! I'm always greatly entertained by any new CPU or gadget. :p

Gotta love those guys, that sort of crap should be in bold in the manuals!
No kidding! I wasted a lot of time wondering why my program (I wrote my own first before trying the app note code) wouldn't work, at all. Startup code should put the CPU into default settings!!! Maybe I'll rewrite the startup code, but probably not. At least I know not to assume anything anymore.

Another reason my own code wouldn't work is that the datasheet/user manual doesn't tell you anywhere (that I could find) that you have to disable access to divisors in U0LCR before the damn thing will work. Who would think of that? Certainly not me. I would have thought something like that would make it NOT work. :p
 
Last edited:
one of the first things we do when things are completely irritating is to get a configuration memory dump and check that nothing got trashed.

Dan
 
if you are connected through JTAG with a debugger, you can stop it and examine any memory location or register you want.
I am, and I can. :D I should have thought of that. Thanks Dan.

I'm having fun playing with the FIFOs. I've never used an MCU with them before. Makes programming serial stuff just slightly different from what I'm used to.
 
I am, and I can. :D I should have thought of that. Thanks Dan.
You're welcome :)
I'm having fun playing with the FIFOs. I've never used an MCU with them before. Makes programming serial stuff just slightly different from what I'm used to.
Well you can still do the serial the same way if you want to, it's just that buffered interrupt driven serial is virtually bullet proof. Especially if you are using the one with the RTS/CTS flow control and a PC!

Dan
 
Last edited:
Ouch, for that price he can keep it! I have been working with ARM7s for over five years. And the NXPs are affordable little power houses! :)
Ya, I doubt I'll buy it. By then I'll be familiar with LPCs.

Hey, my 30-day Crossworks demo ran out and I'm trying to get Eclipse/yagarto to work. But I can't get it to flash the chip at all. I'm using the Zylin CDT. Do you have any clue what gdb init lines to use for that? I've been googling like mad, but I still don't have a clue how to use the debugger and still can't put my programs on the chip.

Sigh... Crossworks is SO easy. Think I'll jump thru their hoops, give em money and get on with programming this thing. :p
 
Sigh... Crossworks is SO easy. Think I'll jump thru their hoops, give em money and get on with programming this thing. :p
Which illustrates the true purpose of a fee but time limited demo.

A similar thing happened to me the CCS 16F aka PCM compiler. I choose to buy the thing rather then port my code. :)

Microchip has the free student version compiler for 32 bit chips. What about the ARM7 is attractive given that you have to buy the compiler ? Are they any compilers in the open source world ?

3v0
 
Ya, I doubt I'll buy it. By then I'll be familiar with LPCs.

Hey, my 30-day Crossworks demo ran out and I'm trying to get Eclipse/yagarto to work. But I can't get it to flash the chip at all. I'm using the Zylin CDT. Do you have any clue what gdb init lines to use for that? I've been googling like mad, but I still don't have a clue how to use the debugger and still can't put my programs on the chip.

Sigh... Crossworks is SO easy. Think I'll jump thru their hoops, give em money and get on with programming this thing. :p
Well Flash Magic - Welcome will flash it.

What functions are you having trouble with?

I am not familiar with those or the GNU tools.

Eclipse Tools is the open source dev sys and macraigor also has a low level debugger if you can get it going it will let you load and execute code. I use it to troubleshoot boards since it lets me view everything and verify all the memory and such.

Dan
 
Which illustrates the true purpose of a fee but time limited demo.
Yup. :p Get em hooked and they'll pay. :D

A similar thing happened to me the CCS 16F aka PCM compiler. I choose to buy the thing rather then port my code. :)
I know what ya mean. I don't have to port code though. It's the same compiler. It's just getting the IDE/debugger working is very difficult. The docs are very poor and there's a LOT of complexity.

What about the ARM7 is attractive given that you have to buy the compiler? Are they any compilers in the open source world?
The compiler is free. It's gnu-arm, or GCC. What you're paying for is a really nice IDE/debugger that works with my ARM-USB-TINY programmer/debugger hardware without any fuss, and libraries, and the fact that everything works out of the box - no config hassles.

Eclipse is a pretty spiffy open source IDE/debugger, but it can be a bugger to set up. Yagarto is a GCC-ARM toolchain, which can also be a pain to set up. If I can get it working I can live with it. Eclipse isn't too bad - not as nice as Crossworks, but for free it's an amazing piece of software.
 
Last edited:
Ya, but I hate using multiple programs. I want my IDE working. And I want debugging to work.

What functions are you having trouble with? I am not familiar with those or the GNU tools.
The ones that I don't know of, that make flashing the chip happen. :D I'll grind at it again tonight. Maybe I'll get it going yet.

Eclipse Tools is the open source dev sys and macraigor also has a low level debugger if you can get it going it will let you load and execute code. I use it to troubleshoot boards since it lets me view everything and verify all the memory and such.
Oh, nice! I'll have a look at that. I'd heard the MaCraigor name, but didn't know anything about it. Thanks Dan. :p
 
Ya, but I hate using multiple programs. I want my IDE working. And I want debugging to work.
Well flashmagic just gets the flash programmed. The hardware involved is a simple RS232 translator between a PC port and the chip UART.
Oh, nice! I'll have a look at that. I'd heard the MaCraigor name, but didn't know anything about it. Thanks Dan. :p
You're welcome. Macraigor is actually in the business of selling HW and SW (we use their stuff for production programmers on more complex stuff, they program off chip flash by loading the flash programing code into the chip RAM and executing from there), but I figure it is a good link for the working versions of everything and there will be other JTAG HW reccomendations.

Dan
 
Well flashmagic just gets the flash programmed. The hardware involved is a simple RS232 translator between a PC port and the chip UART.
For some reason I can't get Flash Magic to connect to the board at all. It should be pretty simple, but... no go.

I have Eclipse/yagarto very close to working. I can compile now. The debugger talks to the hardware. But I still can't get it to flash the chip. Maybe tonight...

EDIT: Just downloaded the IAR Kickstart IDE/Debugger/Compiler and will give that a try tonight. I already use the MSP430 Kickstart version for MSP430's and I don't hate it. It's a bit odd, but works fine. So we will see how it goes for ARMs...

Still not giving up on Eclipse/yagarto though.
 
Last edited:
For some reason I can't get Flash Magic to connect to the board at all. It should be pretty simple, but... no go.
From the user's manual:

"The flash boot loader code is executed every time the part is powered on or reset. The loader can execute the ISP command handler or the user application code. A a LOW level after reset at the P0.14 pin is considered as an external hardware request to start the ISP command handler. Assuming that proper signal is present on X1 pin when the rising edge on RESET pin is generated, it may take up to 3 ms before P0.14 is sampled and the decision on whether to continue with user code or ISP handler is made."

Do you have access to P0.14? And do not forget to stick an RS232 chip inline.

Dan
 
From the user's manual:

"The flash boot loader code is executed every time the part is powered on or reset. The loader can execute the ISP command handler or the user application code. A a LOW level after reset at the P0.14 pin is considered as an external hardware request to start the ISP command handler. Assuming that proper signal is present on X1 pin when the rising edge on RESET pin is generated, it may take up to 3 ms before P0.14 is sampled and the decision on whether to continue with user code or ISP handler is made."

Do you have access to P0.14? And do not forget to stick an RS232 chip inline.
The board has a couple DIP switches to pull P0.14 low and connect another pin correctly for bootloader operation. And it has a SP3232 chip for level conversion. Should work with ease, but I'm missing something (the story of my life :D). Maybe it's as simple as me forgetting to reset the board after moving the DIP switches. :p If I thought of it now I must have thought of it last night, right? Maybe not... :p

I'll grind away at all these things again after work today.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top