lpcware

Writing to GPIO reg

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by graynomad on Sun Jul 08 07:50:10 MST 2012
I told you guys there would be questions :)

I finally received my Xpresso boards, plugged one in and downloaded the few 1000 lines of code I've been writing while waiting for hardware. Blow me down if most things seem to work, software timers with callback functions, all sorts of stuff I've written to get a feel for the system.

And then I hit a brick wall on something that should be a non-event.

I don't seem to be able to write to GPIO0, any of it but let's look at the direction reg.

The actual code uses indexes into lookup tables of pointers etc etc, the debugger verifies that this is working but to get to the nitty gritty the end result is this

   LPC_GPIO0->DIR = 0x80;
Which I think sets P0:7 as an output.

Single stepping and viewing the reg in the debugger shows that the value is not written. The ASM code is as follows (some comments are mine)

     LPC_GPIO0->DIR = 0x80;
movs r3, #160   ; 0xa0
lsls r3, r3, #23   ; 0xA0 << 23 == 0x50000000
movs r2, #128   ; 0x80
str r2, [r3, #32]  ; r3 + 32 ==  0x50000020
Surely this is writing 0x80 into address 0x50000020 AKA the GPIO0DIR register but the debugger still shows 0 in the reg.

I also can't write anything to that (or indeed any) register using the debugger, I can type a value and hit enter but it reverts to 0.

BTW so far I love this system, the above code of course had bugs, one that caused a hard fault, I look back up the stack frame and quickly find a bad index into a list of pointers to functions. That would have taken all night and more to find using printf-debugging on an Arduino or similar.

Outcomes