You are on page 1of 5

ARM : GPIO(General Purpose Input Output Register) |...

http://www.zembedded.com/arm-gpio-general-purpos...

Latest Technology

Latest Gadgets

AVR Projects

Sensors

C pit falls

About Us

HOME

CONTROLLERS

EMBEDDED C

EMBED TOOLS

EMBED INTERFACE

RTOS

LINUX

Search

Home 2013 February 17 ARM : GPIO ( General Purpose Input Output Register )

Recent Post

ARM : GPIO ( General Purpose Input Output Register )


ON: FEBRUARY 17, 2013, BY: ADMIN, IN: ARM MICROCONTROLLERS, 3 COMMENTS

Intel Galileo : Compatible with Arduino software and shields


When every one is gaga on PI, Intel introducing th... more

What are GPIOs?? Share ARM is 32-bit architecture. And that provides 32 bit GPIO ports. In this tutorial, we are going to cover about GPIO pins, how to use them, GPIO registers and an example how microcontroller can interact with outside world with GPIO pins? For this tutorial I am just taking LPC2129 as reference and with the use of CMSIS library and explaining a few lines of code in this tutorial (want to know about CMSIS ??) So, what is GPIO? Whether the peripherals are internal or external that doesnt matter, the core should interact with pins which we call them GPIO pins. Here GPIO pins means, General Purpose Input Output pins. Every peripheral must interact with outside world through these GPIO pins. With the help of GPIO we can easily get connected to basic peripherals like buttons, LEDs, switches and other components. Complex peripherals like GLCDs, TFTs, GPS, different sensors etc. In order to get started with GPIO ports, we need to look into the four registers that controls pins PORTs it: IODIR, IOSET, IOCLR and IOPIN. Each of these registers is explained in detail below with some basic examples of how they work.
LPC2129 PORT PIN description

Thermocouple A temperature sensor


Hi Friends, first and foremost sorry for my absent... more

Whats a Compiler and Compilation?


What's a Compiler and Compilation? A compiler i... more

AVR LCD interfacing : LCD part I


Hi Guys this is my first tutorial on zemebdded sit... more

Arduino MEGA and LEONARDO Pin-Out Diagrams!


Hi Friends please check out these inspiring Ardu... more

IODIR Its 32-bit GPIO. It is used to set the direction of pin. By using this register, we can set a particular pin as input/output. For example, if we want to use our GPIO pin to send signals out from the microcontroller to some external device, we need to set a pin to Output (1). Consider the below example to understand more about this register. Suppose we need to set 0th port 26 th pin as output, the code will be as follows. 1 IODIR0 |= (1 << 26);

ARM : Example Setting PLL for LPC2148


Hi friends this is Partha, this is my second tutor... more

Cortex-M3: Operation Modes & Access Levels


Thanks for the response you guys have shown in ear... more

CORTEX -M3 : Registers in depth


Thanks for the overwhelm response you show in our ... more

IODIR0 is #defined macro in controllers header file.For example, if you set that 0th port 26 th pin then that become output pin. That means we can take the signal from microcontroller through this output pin to the outside world. Note: To set any pin we will use | operation. If we wanted to use our GPIO pin to receive information from the outside world (reading it inside the microcontroller), we would need to set GPIO 0.10 to Input (0). That could be accomplished the following code: 1 IODIR0&= ~(1 << 10);

An intro to Cortex M3 by NXP


In this series of tutorials we take a look into th... more

Note: to set the pin as input pin, you need to use & operation. Sometimes we may want more than one pin as output pins. So, in that case we can accomplish this by setting 1 in those pins as below mentioned line.

In depth LED Blink with NXP LPC17xx


This is going to be a very interesting tutorial fo... more

1 2 3

// Set GPIO 1.14, 1.17, and 1.19 to output IODIR1 |= (1 << 14) | (1 << 17) | (1 << 19);

Categories 8051 Microcontroller (3) Android Tutorials (3)

Like in the same way we can set more than one pin at a time as input pins. IOSET:

1 de 5

17/10/13 02:27

ARM : GPIO(General Purpose Input Output Register) |...


Its 32-bit GPIO. It is used to set the direction of pin. By using this register, we can set a particular pin as input/output.

http://www.zembedded.com/arm-gpio-general-purpos...

ARM Microcontrollers (16) AVR Microcontrollers (15) AVR Projects (3) C pit falls (1) Embed Interface (6) Embed Tools (7) Embedded C (16) Latest Gadgets (12) Latest Technology (46) Linux (3) PIC microcontrollers (2) RTOS (3) Scholars Tips (3) Sensors (1)

If your GPIO pin is set as Output (using the IODIR register mentioned above), you can use IOSET to set your GPIO pin to high (providing a small 3.3V electrical current) or IOCLR to set it to low (providing a connection to GND). Actually, wedont need tothink about high being on and low being off, though, since as well see in the example below you can often turn a device on by setting it low and off by setting it high, depending on how the components are connected. IOPIN: Regardless of whether your GPIO pins direction is set to Input or Output, you can use the IOPIN register to read the current state of every GPIO pin in the pin block. If the value when you read by using IOPIN register is 1 then that pin is currently high, and a 0 value means the pin is currently low. Note: Since IOPIN returns the current state of ALL 32 pins in the pin block, you have to do a little bit of extra work to determine the value of one specific pin. That we can know by using this line of code.
Share

Pin_state = (IOPIN0)&(1<<pin_num)?1:0;

Note: Here IOPIN0 is for 0th port, if you want you can take IOPIN1,IOPIN2 like that

Recent Posts Intel Galileo : Compatible with Arduino software and shields OCTOBER 4, 2013 Thermocouple A temperature sensor
SEPTEMBER 29, 2013

Whats a Compiler and Compilation? JUNE 2, 2013 AVR LCD interfacing : LCD part I MAY 7, 2013 Arduino MEGA and LEONARDO Pin-Out Diagrams! APRIL 10, 2013 CORTEX -M3 : Registers in depth MARCH 20, 2013 Pointers In C FEBRUARY 28, 2013 COMPLEX STRUCTURE DEFINITIONS
FEBRUARY 21, 2013

We can take one example on these registers 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 include "lpc21xx.h" #define #define #define #define BUT1PIN BUT2PIN LED1PIN LED2PIN 15 9 8 10 Subscribe to Blog via Email Enter your email address to subscribe to this blog and receive notifications of new posts by email. Join 46 other subscribers

static void delay(void ) { volatile inti,j; for (i=0;i<100;i++) for (j=0;j<1001;j++); } int main(void) { inti; IODIR0 |= (1<<LED1PIN)|(1<<LED2PIN); // define LED-Pins as outputs IOSET0 = (1<<LED1PIN)|(1<<LED2PIN); // set Bits = LEDs off (active low) IODIR0 &= ~((1<<BUT1PIN)|(1<<BUT2PIN));// define Button-Pins as inputs i=0; while (i<5){ IOCLR0 = (1<<LED1PIN); IOSET0 = (1<<LED2PIN);

Email Address Subscribe

2 de 5

17/10/13 02:27

ARM : GPIO(General Purpose Input Output Register) |...


26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 delay(); IOSET0 = (1<<LED1PIN); IOCLR0 = (1<<LED2PIN); delay(); i++; } while (1) { if (IOPIN0 & (1<<BUT1PIN)) IOCLR0 = (1<<LED1PIN); else IOSET0 = (1<<LED1PIN);

http://www.zembedded.com/arm-gpio-general-purpos...

// true if button released (active low) // clear I/O bit -> LED on (active low) // set I/O bit -> LED off (active low)

if (IOPIN0 & (1<<BUT2PIN)) // true if button released (active low) IOCLR0 = (1<<LED2PIN); // clear I/O bit -> LED on (active low) else IOSET0 = (1<<LED2PIN); // set I/O bit -> LED off (active low) } return 0; // never reached45 }

Share Explanation:

Assume that we are taking Active Low pins In line 1, we added a header file which includes all registers related macros we used in program. So it must be there. 3,4,5,6 lines define the button pins and led pin numbers. In 8th line the delay function starts. In this function we are generating manually a few seconds delay by taking two for loops. Coming to main function, in 19th line we are making LED pin as output pin. And then, in 20th line: by making the LED pins values High, our LEDs will be in OFF state. In 21st line we are making the Button pins as input pins by making zeroes in those pin bits with use of IODIR register. Now, from 23rd line the first line will start. Here, I am taking a condition to repeat this loop for 5 times. And inside the loop, clearing the first LED pin and setting the second LED pin. And then calling the delay function to see the effect of our LEDs glow. After this, I am doing the reverse to those LED pins. Again the same delay function to see the same LEDs effect. From 32nd line the second while loop will start. This second line is infinite one. In this while loop, the first if condition checks the first button pin value is high or not. If the value is high the button is released, so we need to switch off the LED. That we are doing by clearing the first LED pin with use of IOCLR register. In else condition we came to know that the button is still pressed, so we need to switch ON the LED. That we did by setting the LED pin with use of IOSET register. In the second if and else conditions we are doing the same thing for second LED. One sincere request to all the readers, please comment down and correct us, this site is trying to help people to understand embedded technology, this is only possible with your comments and corrections. Please subscribe to the newsletter to get latest project/article updates right in your email inbox. Take few moments and like zembedded facebook page, follow on tweeter, thanks!

Related posts:

ARM LPC2000: Interrupt system

Cortex M3 SysTick Explained - Part II

An intro to Cortex M3 by NXP

ARM : Example Setting PLL for LPC2148

Share this post:

Tweet

Like

44

About author
This article was written by admin Admin has over twenty years experience in the electronics industry, largely dedicated to embedded software. A frequent presenter at conferences and seminars and author of numerous technical articles. Working presently as Development Manager in India. A firm Believer in Knowledge grows when it shared.

3 de 5

17/10/13 02:27

ARM : GPIO(General Purpose Input Output Register) |...

http://www.zembedded.com/arm-gpio-general-purpos...

Related Posts
ARM : Example Setting PLL for LPC2148 - April 4, 2013 Cortex-M3: Operation Modes & Access Levels - March 22, 2013 Cortex M3 SysTick Explained Part II - February 26, 2013 Cortex M3 SysTick Explained Part-I - February 5, 2013 NXP offers emWin free with ARM Microcontrollers - February 3, 2013

Comments
tarik from algeria says - POSTED: MARCH 8, 2013
hello, 1-does it mean that LED1PIN and LED2PIN are in High (3.3 V) because IOSET0 mean high: IOSET0 = (1<<LED1PIN)|(1<<LED2PIN); // set Bits = LEDs off (active low)
Share

Comments (3)

2if (IOPIN0 & (1<<BUT1PIN)) // true if button released (active low)where is the condition please IOCLR0 = (1< LED on (active low) why LED on but we know that IOCLR0 means LOW (grd) else IOSET0 = (1< LED off (active low) thank you very much Reply

Pardhu says - POSTED: MARCH 10, 2013


Hi Tarik, 1. if you set the pins HIGH, its not mean that LEDs should turn on. It depend up on how you connected your LEDs with controller. see this link, you may get idea on this. http://itis4all.blogspot.in/2013/03/led-pin-connections.html 2. To under stand this you just need basic knowledge about if statement. if(1) The condition is satisfied to get execute the if block. if(0) The condition fails so, it goes to else block or next statement. Reply

tarik from algeria says - POSTED: MARCH 12, 2013


thank you very much friends Reply

Leave a Reply

4 de 5

17/10/13 02:27

ARM : GPIO(General Purpose Input Output Register) |...

http://www.zembedded.com/arm-gpio-general-purpos...

RECENT POST
Intel Galileo : Compatible with Arduino software and shields October 4, 2013 Thermocouple A temperature sensor September 29, 2013 Whats a Compiler and Compilation? June 2, 2013 AVR LCD interfacing : LCD part I May 7, 2013 Arduino MEGA and LEONARDO Pin-Out Diagrams! April 10, 2013 ARM : Example Setting PLL for LPC2148 April 4, 2013 Cortex-M3: Operation Modes & Access Levels March 22, 2013 CORTEX -M3 : Registers in depth March 20, 2013

RECENT COMMENTS
nethra on COMPLEX STRUCTURE DEFINITIONS jal on Thermocouple A temperature sensor nethra on Thermocouple A temperature sensor nethra on CORTEX -M3 : Registers in depth ankush on ARM : Example Setting PLL for LPC2148 ankush on ARM : Example Setting PLL for LPC2148

DISCLAIMERS AND NOTICES www.zembedded.com do not take any responsibility to the contents added in this site. we just search and collect data from popular article directories and use search engine to collect the best information for you. We really strict about copyright but however, if you feel that any of these contents are violating the copyright rules, please let us know. we will exclude it as soon as possible. Please contact us with your exact grievance/problem with respect to those third party links. We assure you that appropriate action will be taken immediately. Thanks Email: admin@zembedded.com

ZEMBEDDED Zembedded
Me gusta A 1015 personas les gusta Zembedded.

Plug-in social de Facebook

- Facebook Members WordPress Plugin

Share

Copyrightzembedded.com

Back to top

5 de 5

17/10/13 02:27