Warning: total newbie here. I'm trying to learn ARM (have not tried to program it yet, but have plans to do so) and I was looking through examples and couldn't find an explanation for IODIR1 variable setting. Most examples set this variable to like this:
Code:
IODIR1=0x00FF0000;
with comment that this initializes pins P1.16 - P1.23 (8 pins).
My question is, how does a such a big number initialize pins 16 - 23 and where could I find the explanation? The AVR code for instance (DDRB) I understand, but this is puzzling. I have a small dev board and LPC1113 for playing around, but would like to understand the code and what it does before I try to connect the chip. For instance, how would I set just pin1.1 as output?
In a few words IODIR is a 32bit register, 0x00FF0000 equals 0b00000000111111110000000000000000 , 1 in a bit means that the pin is set as output while 0 means input.
Thanks! I did read the insiders guide, and I will surely check out ARMwizard!. The user manual does not contain IODIR at all (perhaps under a different name?) and Insiders Guide only used the before mentioned value. Me being new to this, I do miss a tutorial for ARM like the ones for AVR.
You can see IODIR in section 12.3.2 but the name is not exactly the same , it is GPIO0DIR, GPIO1DIR, GPIO2DIR,GPIO3DIR
The Cortex devices use the CMSIS library and all the registers are defined as structures (a look in LPC11xx.h will help) so all the pin registers are accessed using
Thanks for the explanation on the structures. Regarding the PINSEL (although, I'am already off topic here): The PINSEL as far as I understand it is used to define which function does the specified pin have (whether it is GPIO or something else (e.g. PIO2.1 can be PIO2_1, DSR or SCK1). The manual mentions (chapter 7.4.9) IOCON_PIO2_1 register name. So if I am understanding this correctly (note that this is just a made up example), given the lpc11xx.h (downloaded from Keil website), if I wanted pin PIO2_1 to behave as SCLK1, I would code it by setting LPC_IOCON->PIO2_1 = 0x2 (as per user manual, page 77)?
And I have another question, but so off topic that I'll just create a new thread for it. Thank you, you've been a great help to me!
You are partially correct because if you use LPC_IOCON->PIO2_1 = 0x2 then in addition to selecting SCK1 you set all other bits to 0 but note that there are bits like 7:6 in this case which are reserved and should always be left to the default value (1 in this case).
You also disable the pullup resistor which is enabled by default but maybe this is something you want to do.
You are partially correct because if you use LPC_IOCON->PIO2_1 = 0x2 then in addition to selecting SCK1 you set all other bits to 0 but note that there are bits like 7:6 in this case which are reserved and should always be left to the default value (1 in this case).
The example is made up -- just to see if I understand. So I should be using LPC_IOCON->PIO2_1 |= (LPC_IOCON->PIO2_1 & 0xffffff00) | 0x02 then? To leave all the other bits untouched?
0xffffff00 equals 0b11111111111111111111111100000000 so it clears b7:0 , the correct value in this case is 0xfffffff8 which equals 0b11111111111111111111111111111000 since you only want to change b2:0 which are responsible for the pin function.