LPC-P2148 "The big getting started guide"

futz:

leon_heller:
ARM chips are usually debugged and programmed with a JTAG interface. I have a design for a parallel port I/F if you want to build your own.

Ya, but who has a parallel port anymore? Only the oldest klunkers here in the swamp have parallels, and I don't use those old machines for programming (I hardly use them at all). I'm too impatient! :mrgreen:

People often ask about a DIY parallel port JTAG on the LPC2000 forum.

Leon

I have no idea what UART logging is. Never heard of it.

I finally found the link back (after 2 hours orso)

Check the link http://www.optixx.org/category/arm/ and scroll down until you find “SIO Debug Console”

If you use JTAg for programming this would be ideal to debug as you go.

KidE:

I have no idea what UART logging is. Never heard of it.

I finally found the link back (after 2 hours orso)

Check the link http://www.optixx.org/category/arm/ and scroll down until you find “SIO Debug Console”

If you use JTAg for programming this would be ideal to debug as you go.

If you have JTAG then using that silly thing is ridiculous. Why bother when JTAG does it far better and easier?

That cobbled together serial debugger is for poor wretches who have no JTAG. :mrgreen:

That said, using anything you want to for debugging purposes is fine. I’ve used everything from a single LED to serial (as above) to a 7-seg LED display to an LCD. But all those mean writing extra test code.

A real debugger lets you watch and control your existing code as it runs on the hardware, without adding bunches of test code that could alter the behaviour of your existing code if you aren’t real careful.

I tried to build your LED buzzer thing with LPC210x.h but that is giving some problems which i have to dig into.

Why don't we get on the same page here. Grab "my" (not really mine - I downloaded it from somewhere) [[LPC214x header file](http://ghmicro.com/images/junk/LPC214x.rar). It has worked just fine since I started out. [/quote]

Ok i build it in crossworks and also debugged it to the chip and the result is

Executing reset script FLASHReset()

Loading target script file C:\Program Files\Rowley Associates Limited\CrossWorks for ARM 1.7\targets\Philips_LPC210X\Philips_LPC210X_Target.js
Downloading “Loader_rpc.elf” to Olimex ARM-USB-OCD
Programming completed in 63 ms — 89,079 bytes/sec
Programming 5.4 kB of addresses 40000000 — 400015eb
Download complete
Verifying “Loader_rpc.elf” on Olimex ARM-USB-OCD
Verifying completed in 140 ms — 40,085 bytes/sec
Verifying 5.4 kB of addresses 40000000 — 400015eb
Verify complete
Downloading “ledbeep.elf” to Olimex ARM-USB-OCD
Erasing completed in 516 ms — 5,488 bytes/sec
Erasing 2.7 kB of addresses 00000000 — 00000b0f
Programming completed in 234 ms — 12,102 bytes/sec
Programming 2.7 kB of addresses 00000000 — 00000b0f
Download complete
Verifying “ledbeep.elf” on Olimex ARM-USB-OCD
Verifying completed in 203 ms — 13,950 bytes/sec
Verifying 2.7 kB of addresses 00000000 — 00000b0f
Verify complete
Executing reset script FLASHReset()
Loading target script file C:\Program Files\Rowley Associates Limited\CrossWorks for ARM 1.7\targets\Philips_LPC210X\Philips_LPC210X_Target.js




So eyy this part worked :lol: 



Only after a powercycle of the board nothing happens :cry: 



So this should be time how to use the debugger right?



but ehh how do i do that?](http://ghmicro.com/images/junk/LPC214x.rar)

You need STARTUP_FROM_RESET. See the Rowley FAQs on their web site.

Leon

KidE:
Only after a powercycle of the board nothing happens :cry:

So this should be time how to use the debugger right?

but ehh how do i do that?

Click on Reset and Debug. Then click on the Run icon.

I’m going from foggy memory, so adjust to suit. My Crossworks demo doesn’t work anymore. :mrgreen:

Or put it in your code as Leon suggests.

leon_heller:
You need STARTUP_FROM_RESET. See the Rowley FAQs on their web site.

Leon

Ok i tried adding STARTUP_FROM_RESET to the proprocessor properties of the main.c file without any luck :cry: still having the same issue

Click on Reset and Debug. Then click on the Run

Rest and Debug = OK :smiley: but the RUN icon :?:

So OK i admit i’m the error “between keyboard and chair” but i dont see a damm RUN icon :? i found a GO button (F5) but that didnt do much good here

KidE:
Rest and Debug = OK :smiley: but the RUN icon :?:

So OK i admit i’m the error “between keyboard and chair” but i dont see a damm RUN icon :? i found a GO button (F5) but that didnt do much good here

It's one of those icons up there. In most debuggers there's a run, halt, step into, step over, reset and some other things. Go thru the debugging docs and you'll be up to speed in no time.

I see there’s a Start Without Debugging icon (CTRL - F5). Try that.

EDIT: Looked at the menu. GO should work.

Are you testing my buttons/piezo beeper code? When running it won’t appear to do anything till you press buttons. Maybe that’s what’s throwing you?

Hello KidE,

Ok i tried adding STARTUP_FROM_RESET to the proprocessor properties of the main.c file without any luck

You need STARTUP_FROM_RESET for the startup file.

Regards,

mifi

futz:
Are you testing my buttons/piezo beeper code? When running it won’t appear to do anything till you press buttons. Maybe that’s what’s throwing you?

Ahh i maybe appear a bit stupid but trust me i’ts not that bad!

futz:
I see there’s a Start Without Debugging icon (CTRL - F5). Try that.

EDIT: Looked at the menu. GO should work.

Ok i didnt realize that after RUN i should push a button :lol: This work now and i understand what you mean with anoying sounds :wink:

I powercycled the board instead of leaving the JATG connector connected.

After powercyle it doesnt work but that is probably due to the STARTUP_FROM_RESET.

mifi:
You need STARTUP_FROM_RESET for the startup file.

Sorry about that i dindt know you ment the blabla Startup.s file :green:

For now i’ll party here because finally i have it working :stuck_out_tongue: :stuck_out_tongue:

OK 2nd hurdle is taken, tnx for all help guys

where the hell have i gotten myself into learning this stuff for fun

Cheers

So ifiddles around with the code and i see that “IOPIN0 ^= 0x000000400;” put the LED ON. Setting “IOPIN0 ^= 0x000000400;” for the second time puts the LED OFF again.

But in the second part i see “IOPIN0 ^= 0x00000800” that does the same only for LED 2.

So i’m a bit off track. Do i need to see IOPIN0 as the variable and 0x00000800 as its value? if yes This value sets a certain port ON or OFF but how do i find out that 0x00000800 is the pin for LED2?

If i look at the scematics i see LED2 is connected P0.11 http://www.olimex.com/dev/images/ARM/LP … -D-sch.gif and some other things behind it but no adresses.

Also in the LPC214x.h file i stranded without adresses

KidE:
So ifiddles around with the code and i see that “IOPIN0 ^= 0x000000400;” put the LED ON. Setting “IOPIN0 ^= 0x000000400;” for the second time puts the LED OFF again.

But in the second part i see “IOPIN0 ^= 0x00000800” that does the same only for LED 2.

So i’m a bit off track. Do i need to see IOPIN0 as the variable and 0x00000800 as its value? if yes This value sets a certain port ON or OFF but how do i find out that 0x00000800 is the pin for LED2?

IOPIN0 is a register that contains the state of Port0. You may need to study the User Manual GPIO section to clarify what I mean by this. ^= is an exclusive OR.

“IOPIN0 ^= 0x000000400;” toggles one bit (one of the LEDs) of Port0. The exclusive OR just reads the bit and makes it the opposite of its current state. 0x000000800 is the bit for the other LED.

If i look at the schematics i see LED2 is connected P0.11 http://www.olimex.com/dev/images/ARM/LP … -D-sch.gif and some other things behind it but no adresses.

11 is the bit number in the 32-bit Port0. The bits go from P0.0 to P0.31. You understand hex and binary? You will need to understand both fluently to do this. If not, start studying. :mrgreen:

Also in the LPC214x.h file i stranded without adresses

Not sure what you mean by that one... Why do you need addresses? That's what the equates in the include file are for. You can use the register names, and don't have to know their addresses. MUCH easier that way. This isn't assembly language, not that you'd normally do it that way there either.

futz:
You will need to understand both fluently to do this. If not, start studying.

Trust me if i say that this is not the only thing i need to study :mrgreen:

I’ll resumé to see i’f i’m correct so correct me if i’m wrong

If i look at the user manual I see that there are 2 32BIT I/O ports available.

PORT0 has 31 PIN’s / BITS I/O and 1 PIN/BIT only O (PIN 32) P0.0/P0.31

PORT1 has 16 PIN’s (32 BIT’s??) I/O P1.16/P1.31

The other pins are for power, reset and other stuff i dont understand :lol:

All BITS in PORT0 & 1 have 4 registers which control the state of the port.

or do PORT0 & 1 both have 2 x 4 registers?

Are the registers the arguments before the P0.11 at the left in the schematic CTS/CAP1.1 ??http://www.olimex.com/dev/images/ARM/LP … -D-sch.gif

I realize i have to learn more than i expected but every help is really appreciated.

KidE:
If i look at the user manual I see that there are 2 32BIT I/O ports available.

PORT0 has 31 PIN’s / BITS I/O and 1 PIN/BIT only O (PIN 32) P0.0/P0.31

PORT1 has 16 PIN’s (32 BIT’s??) I/O P1.16/P1.31

Just checking, but by User Manual you mean the UM10139 document, right? Look at Chapter 8 in there. The index is at the end (yes, it's backwards!).

Port0 has 32 pins/bits, not 31. When working with computers, things start at 0 and count up from there (not from 1 as you’re used to in the analog/meat world).

Port1 is mostly (maybe completely - I could be wrong) eaten up by the JTAG, so it’s not available for your use while you’re using JTAG.

The other pins are for power, reset and other stuff i dont understand :lol:

Don't sweat that. You'll need to understand it all eventually, but it will come.

All BITS in PORT0 & 1 have 4 registers which control the state of the port. or do PORT0 & 1 both have 2 x 4 registers?

IODIR0 and IODIR1 - control the data direction of each GPIO pin (input or output)

IOPIN0 and 1 - You can read the status of a port with this, or write to all pins at once with it. It contains the status of the port.

IOCLR0 and 1 - Any bit you set in this register clears that bit in the respective port. The zero bits are unaffected.

IOSET0 and 1 - Any bit you set in this register sets that bit in the respective port. The zero bits are unaffected.

Study my newb code on my site while following along in the User Manual to see how these work. They’re pretty straightforward.

Are the registers the arguments before the P0.11 at the left in the schematic CTS/CAP1.1 ?

NO! Those are the other functions that those pins are multiplexed with. Each pin can be set to any one of those modes by using the pin connect block (PINSEL). On reset all pins in Port0 are set to GPIO. Your program can and will change that to suit what you want the pins to do.

For instance: Look at my SPI code. You’ll see that I use PINSEL to tell the chip that I want the SPI pins to be SPI pins, and not GPIO. Same goes for any peripheral you want to use. Once they’re in use as peripheral I/O pins rather than GPIO the IODIR no longer has any effect.

I realize i have to learn more than i expected but every help is really appreciated.

If you're already learning more than you expected then your expectations are several quantum leaps too low. These are very complex little machines! You're barely scratching the surface, my friend. Never mind that. You're barely sniffing the surface still. You'll scratch at it a bit soon. :mrgreen: **LONG** way to go.

futz:
Port0 has 32 pins/bits, not 31. When working with computers, things start at 0 and count up from there (not from 1 as you’re used to in the analog/meat world).

Like i sayd:

PORT0 has 31 PIN’s / BITS I/O and 1 PIN/BIT only O (PIN 32) P0.0/P0.31

PORT1 has 16 PIN’s (32 BIT’s??) I/O P1.16/P1.31

Starting from 0 port0 has 31 pins I/O and 1 pin only O (pin 32)

This depends on the function as i look in the manual

I’ve been a UNIX admin for the last 9 years so thinking in zero & one is in my confort zone :mrgreen:

futz:
Port1 is mostly (maybe completely - I could be wrong) eaten up by the JTAG, so it’s not available for your use while you’re using JTAG.

If i look at the schematic i see port1 is bussed to JTAG but at the connector i see pins P1.16/P1.25 breaking out again while P1.26/P1.31 are connected to the JTAG connector

futz:

Are the registers the arguments before the P0.11 at the left in the schematic CTS/CAP1.1 ?

NO! Those are the other functions that those pins are multiplexed with. Each pin can be set to any one of those modes by using the pin connect block (PINSEL). On reset all pins in Port0 are set to GPIO. Your program can and will change that to suit what you want the pins to do.

For instance: Look at my SPI code. You’ll see that I use PINSEL to tell the chip that I want the SPI pins to be SPI pins, and not GPIO. Same goes for any peripheral you want to use. Once they’re in use as peripheral I/O pins rather than GPIO the IODIR no longer has any effect.

Lets take PORT0 as an example:

All pins (except 32) have multiple functions which you can select with PINSEL to tell the chip which function that pin has. right?

All functions have 4 registers for controlling the “active” function of that pin. right?

So if “IOPIN0 ^= 0x00000800” Where IOPIN0 is the register and 0x00000800 is the bit for the LED.

The OR Looks at 0x00000800 and changes the state to the opposite!

This is getting more clear now 8)

But only 1 thing i dont (not yet at least) understand is where do i find that bit 0x00000800 belongs to that LED and that specific pin?

Looking at the manual i dont find it

KidE:
Like i said:

PORT0 has 31 PIN’s / BITS I/O and 1 PIN/BIT only O (PIN 32) P0.0/P0.31

PORT1 has 16 PIN’s (32 BIT’s??) I/O P1.16/P1.31

Starting from 0 port0 has 31 pins I/O and 1 pin only O (pin 32)

This depends on the function as i look in the manual

Ah, I see what you were getting at. Ok then. I agree. :mrgreen:

If i look at the schematic i see port1 is bussed to JTAG but at the connector i see pins P1.16/P1.25 breaking out again while P1.26/P1.31 are connected to the JTAG connector

That's so you can use them for General Purpose I/O when the JTAG isn't being used. If you really need those pins then you're going to have to bootload your code.

Lets take PORT0 as an example:

All pins (except 31) have multiple functions which you can select with PINSEL to tell the chip which function that pin has. right?

Correct.

All functions have 4 registers for controlling the “active” function of that pin. right?

Correct.

But only one thing i don’t (not yet at least) understand is where do i find that bit 0x00000800 belongs to that LED and that specific pin?

Looking at the manual i dont find it

For that you look at the schematic. On this board there happens to be LEDs on pins P0.10 and 11. (On other boards those pins might go to other things). P0.10 is bit-10 of Port0, and P0.11 is bit-11 of Port0 (counting from zero always). Each of the 32 pins corresponds to one bit of an int (32-bits). So to make it easy just scribble this out on paper. In Port0 there are four bytes (32-bits)
    4           3           2           1
7654 3210 : 7654 3210 : 7654 3210 : 7654 3210

The bits are numbered as follows. Again, I’ve separated the bytes for clarity:

31 30 29 28 27 26 25 24 : 23 22 21 20 19 18 17 16 : 15 14 13 12 11 10 09 08 : 07 06 05 04 03 02 01 00

Each of those bits corresponds to one pin of P0:0 to P0:31.

Each byte is 8 bits as above. In a byte there are two nybbles of 4 bits each. Like this:

3210

The values of those 4 bits are as follows:

8421

Add those four values up if all bits are set and you get 0xf for the nybble. Put two nibbles together with all bits set and you get 0xff. You can use this as a quick way to convert binary to hex in your head.

Another quick example. A byte:

0110 1010

Quick conversion to hex goes like this. The top nybble has the 2 and 4 bits set. It’s 0x6. The low nybble has the 8 and 2 bits set. That’s 0x0a (10 decimal). The whole byte’s value is 0x6a. Simple, right? :mrgreen:

So anyway, 0x00000800 means that the 8 bit of the second from lowest byte of Port0 is set, or bit-11. Count from the right starting at zero. 0 1 2 3 4 5 6 7. That’s the lowest byte. Then into the second byte with 8 9 10 11 (but think the values of the bits in the nybble, which are 1 2 4 8 ). The 8 bit in the low nybble of that second byte is set. Thus P0.11, or 0x00000800.

Let’s diagram that out. 0x00000800 would be like this:

31 30 29 28 27 26 25 24 : 23 22 21 20 19 18 17 16 : 15 14 13 12 11 10 09 08 : 07 06 05 04 03 02 01 00

See the red bit? That’s our 8 position in that nybble (bit 3 of the byte).

Confused yet? You will be. You WILL be. But then it will all make sense. To program computers you MUST be able to think in hexadecimal and binary and translate back and forth without having to think too much about it. A hex/binary/decimal converter calculator can be a help sometimes too.

Don’t be offended if I go too newb on ya. I don’t know for sure what you know or don’t know. I err on the side of ultra newbness. :mrgreen:

Confused yet? You will be. You WILL be

Well i was :lol: but then something came back to me from a long time ago when i was still hunting girls with a wooden bat :mrgreen:

32 bits

31 30 29 28 27 26 25 24 : 23 22 21 20 19 18 17 16 : 15 14 13 12 11 10 09 08 : 07 06 05 04 03 02 01 00

Taking the 3rd byte:

15 14 13 12 11 10 09 08

Taking the 2nd nibble

11 10 09 08

The value of the bits in the second nibble

11=8 10=4 09=2 08=1

Putting all bits in the nibble ON results in

1 1 1 1 in binary = F in hex

All bits ON in the byte

1 1 1 1 1 1 1 1 in bin = FF in hex is 255 in dec

All 32 bits ON

FF FF FF FF in hex = 255 255 255 255 in dec

Reminds me of calculating netmasks for networking :wink:

OK i’m on the roll here :mrgreen:

going back to “IOPIN0 ^= 0x000000800;”

This makes 0x000000800 bit number 11

and

This makes 0x000000400 bit number 10

Any correction needed so far?

So where do the registers come in?

BTW i’m absolutely not offended in any way! getting things explainend in a simple way make life much more easy sometimes :wink:

Ok i came across something weird in your code

		if((IOPIN0 & 0x00008000) == 0){		//button 1 pressed?
                        IOPIN0 ^= 0x000000400;		//LED 1 ON
			for(i=100;i<2500;i+=5){		//annoying ascending tones

In the 1st i see “0x00008000” which has 8 characters after the 0x

In the 2nd i see “0x000000400” which has 9 characters after the 0x :?:

“0x00008000” = BUTTON1 on P.015

So

LED1 should be on “0x00000400” if my calc is right. How can it ben that LED1 has 1 more 0 stuck to it?

i’ve put ```
IOPIN0 ^= 0x00200000;

in the code right below the ```
IOPIN0 ^= 0x00000400;
``` so if LED1 is on this should turn P0.21 ON because its a normal GPIO pin right?

If i measure between P0.21 and 3.3V i do not see anything here 

Did i forgot anything?