PDA

View Full Version : need help with ARM lpc2148...



shashankiim
12-11-2009, 06:26 PM
Hi
I am a beginner at ARM microcontrollers ( just shifted to them from AVRs)
I have been trying to write programs for LPC2148 but with limited success.

Following is the code I wrote for blinking the LEDs on the board.
However the output is weird. 4 leds just stay on and rest off.

Following code was written on KEIL uVISION.
It compiles perfectly and produces the .hex file.


#include <LPC214X.H>

int delay(void);

int main(void)
{

PINSEL0 = 0x00000000;

IO0DIR = 0xffffffff;


while(1)
{
IO0SET = 0xffffffff;
delay();

IO0CLR = 0xffffffff;
delay();
}


return 0;
}

int delay(void)
{
unsigned long int i;

for( i = 0; i < 1000000; i++);

return 0;
}



Why is the output not proper? What additional setups have to be done in the code ? Any help in this regard will be greatly appreciated.

PS : Is there any good place or site I can refer which helps in smooth migration from AVRs to ARMs ?
(Google in this regard was of little help).

Eagerly waiting for a reply...
Thanks in advance
Shashank

biscuit
12-15-2009, 03:59 PM
first i have to accept that i have no experience in ARM

but i think i can add a few comments to your code

int delay(void)
{
unsigned long int i;

for( i = 0; i < 1000000; i++);

return 0;
}


When the compiler optimises it it sees that it performs no useful stuff and optimises it away

so i think the pin remains high at all time and depending on the LED connection might be on or off

i would suggest you to use only switching on the LED by using either

IO0SET = 0xffffffff;

or

IO0CLR = 0xffffffff;

Just to reiterate ... i have no arm experience and the registers i am suggesting are just a copy from your code

shashankiim
12-15-2009, 07:20 PM
hi biscuit

thanks for the reply...

but still this won't solve the problem i tried it earlier !!!
i suppose that there are some other registers also to be set up (i guess!) before the uc starts functioning...

i suppose ARMs are not as easy as AVRs :)

neways thanks for the reply...

ps: and for anybody who knows a solution please reply...!!

imhardikshah
12-16-2009, 10:55 AM
Hi,
I think so the code is correct, only the problem is that you need to add the proper start code while you have created a new project and set the proper linker script.

To set the proper startup code

Open the Startup.S file by clicking in the project Workspace (on top-left corner) and select
the Configuration Wizard tab (bottom of the source window).
Now Select the VPBDIV Setup checkbox and change the VPBDIV:VPB Clock option menu as VPB Clock = CPU Clock (if you want the same).

To set the proper Linker script
go to the Options for Target by right clicking the Target in the project window
and in the Linker tab check on Use Memory layout from target Dialog and press OK
(This worked for me :) ). Or which ever your board configuration is select that..

Regards,
Hardik Shah

elecrom
12-17-2009, 07:47 PM
- What is your crystal frequency ?
- Even I had noticed this problem of for loop becoming ineffective, I tried this solution and it worked.

int delay(void)
{
unsigned long int i; // >> LONG INT ? in keil, int => 32 bits, thats huge.
unsigned int x;

for( i = 0; i < 1000000; i++)
x = x + i; //some crap, so that compiler will not remove 'for' loop.

return x;
}

and also in Target>options, under "C/C++" tab, select highest optimization level and check "optimize for Time".

Try this and post ur results.

wizardjack
12-17-2009, 08:19 PM
@elecom

Depending on how you call delay(), compiler might still optimize it way. You may want to declare i as volatile. Compiler should never optimize a volatile.

void
delay(void)
{
volatile unsigned long int i; // >> LONG INT ? in keil, int => 32 bits, thats huge.

for( i = 0; i < 1000000; i++)
;

return;
}

You can find sample code at NXP website,
http://www.standardics.nxp.com/support/documents/microcontrollers/?scope=LPC2148&type=software

shashankiim
12-17-2009, 10:11 PM
thank you all for your replies..

the code posted initially is working perfectly now...

i was using the UART programming ISP procedure and also supplying the power through same header. i suppose when i remover the uart wires and left only the power supply the output is perfect however when with the wires of the uart are also connected the output is not working...

i suppose this might be the source of error.. though no idea why ... :)

the leds were on P1.16 to P1.23...

thank you all for your help...

however now i have new problem...

1. FAST GPIO :

not able to work with the fast GPIO ( except from CSC register any other thing to set up ) ??

2. COMPILER :
why am i not able to use the pin symbols in the register...

for example in AVR studio to set a bit high we can give a command as

PORTB |= ( 1 << PB3); // PB3 is a #define symbol like #define PB3 3

however in uVISION such lines give an error...
does it mean they can not be programmed like this....?


please help me in this regard...
thanks in advance
shashank