Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] ARM IODIR explanation

Status
Not open for further replies.

skyflyer

Newbie level 4
Joined
Jul 14, 2012
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,327
Hi!

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?

Thanks,
Miha.
 
Last edited:

The IODIR register is the same in all NXP models so a read of The Insider's Guide To The NXP LPC2300/2400 Based Microcontrollers will help you
https://www.hitex.com/index.php?id=download-insiders-guides

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.

For P1.1 as output use 0x00000001

Also download ARMwizard , it will help you with a lot of settings https://www.edaboard.com/threads/196143/#post1105524

- - - Updated - - -

Also download the user manual where the function of all registers is explained
www.nxp.com/documents/user_manual/UM10398.pdf
 

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.

Thanks,
Miha.
 

Did you download the user manual?
It is www.nxp.com/documents/user_manual/UM10398.pdf

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

Code:
LPC_GPIO0->DIR
LPC_GPIO1->DIR
LPC_GPIO2->DIR
LPC_GPIO3->DIR

This is the same as DDR in AVR

Also

Code:
LPC_GPIO0->DATA
LPC_GPIO1->DATA
LPC_GPIO2->DATA
LPC_GPIO3->DATA

which is the same as PORT in AVR (when set for output)

Usually it is convenient to use shift operators because it is hard to count all the bits so to set P1.20 as output all you have to do is
Code:
LPC_GPIO1->DIR |= (1UL<<20);  // UL stands for unsigned long
 

Did you download the user manual?
It is www.nxp.com/documents/user_manual/UM10398.pdf

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.

- - - Updated - - -

and replace |= with =

Code:
LPC_IOCON->PIO2_1 = (LPC_IOCON->PIO2_1 & 0xfffffff8) | 0x02
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top