EmbeddedRelated.com
Forums

LPC2478 loop and LED on Olimex SDK

Started by "jim.deas" July 11, 2009
I am new to the LPC series and using GCC compilers so please forgive me if this is a simple issue.

I have managed to configure Eclipse and the associated tools to compile and download code to the Olimex card. After a few days of trial and error I found the following unexplainable operation.
The two code fragments below should blink one of the LEDs on the PCB. The only difference is the first one runs a delay loop then fires a single set/reset to the LED port. The other sets and resets the port during the loop.

Why would this not work? Is it possible that the loop is being optimized out by GCC? On the failed one below the LED remains off.
This code works using IOSET/IOCLR or simply IOPIN:

while (1) {
for (j = 0; j < 500000; j++ )
IOPIN1 &=~0x00040000;
for (j = 0; j < 500000; j++ )
IOPIN1 |=0x00040000;
}
}

This code fails:
while (1) {
for (j = 0; j < 500000; j++ );
IOPIN1 &=~0x00040000;
for (j = 0; j < 500000; j++ );
IOPIN1 |=0x00040000;
}
}

An Engineer's Guide to the LPC2100 Series

Hi Jim,

I don't see the difference between working and not working code.

Anyway, IOPIN refers to pin state. Hence you cannot set it. You can only read from it. To set/reset GPIO pin, use IOSET and IOCLR. Those registers connected to internal D-latch behind the pins. To enable the D-latch, use IODIR.

Regards,
-daniel

--- On Fri, 7/10/09, jim.deas wrote:

I am new to the LPC series and using GCC compilers so please forgive me if this is a simple issue.

I have managed to configure Eclipse and the associated tools to compile and download code to the Olimex card. After a few days of trial and error I found the following unexplainable operation.

The two code fragments below should blink one of the LEDs on the PCB. The only difference is the first one runs a delay loop then fires a single set/reset to the LED port. The other sets and resets the port during the loop.

Why would this not work? Is it possible that the loop is being optimized out by GCC? On the failed one below the LED remains off.

This code works using IOSET/IOCLR or simply IOPIN:

while (1) {
for (j = 0; j < 500000; j++ )
IOPIN1 &=~0x00040000;
for (j = 0; j < 500000; j++ )
IOPIN1 |=0x00040000;
}

This code fails:

while (1) {
for (j = 0; j < 500000; j++ );
IOPIN1 &=~0x00040000;
for (j = 0; j < 500000; j++ );
IOPIN1 |=0x00040000;
}

Whoops..sorry. I was referring AT91 while commenting on this one. Sorry.

I remembered that I tried IOPIN to set/reset before, but my colleague told me that it was not suggested, but didn't told me the reason. So, I guess, now I know why =)

-daniel

--- On Sun, 7/12/09, Daniel Widyanto wrote:

From: Daniel Widyanto
Subject: Re: [lpc2000] LPC2478 loop and LED on Olimex SDK
To: l...
Date: Sunday, July 12, 2009, 2:35 PM

Hi Jim,

I don't see the difference between working and not working code.

Anyway, IOPIN refers to pin state. Hence you cannot set it. You can only read from it. To set/reset GPIO pin, use IOSET and IOCLR. Those registers connected to internal D-latch behind the pins. To enable the D-latch, use IODIR.

Regards,

-daniel