Difference between revisions of "Embedded System Tutorial GPIO"

From Embedded Systems Learning Academy
Jump to: navigation, search
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
Socialledge is moving to two portals. 
 +
*  The Wiki will remain here for general references about the SJ-One board, and to document student reports.
 +
*  The bookstack will now be used for SJSU assignments
 +
 +
[http://books.socialledge.com/books/embedded-drivers-real-time-operating-systems/chapter/lesson-gpio This article has been moved here]
 +
 +
<!--
 
== Objective ==
 
== Objective ==
 
Interface your LPC17xx to a switch and an LED.
 
Interface your LPC17xx to a switch and an LED.
Line 11: Line 18:
 
*  You should know fundamentals of electricity and the famous '''V = IR''' equation.
 
*  You should know fundamentals of electricity and the famous '''V = IR''' equation.
  
== Lecture ==
+
== GPIO ==
 +
{| class="wikitable"
 +
|-
 +
|
 +
GPIO stands for "General Purpose Input Output".  Each pin can at least be used as an output or input.  In an output configuration, the pin voltage is either 0v or 3.3v.  In input mode, we can read whether the voltage is 0v or 3.3v.
 +
 
 +
You can locate a GPIO that you wish to use for a switch or an LED by first starting with the schematic of the board.  The schematic will show which pins are "available" because some of the microcontroller pins may be used internally by your development board.  After you locate a free pin, such as P2.0, then you can look-up the microcontroller user manual to locate the memory that you can manipulate.
 +
 
 +
|[[File:tutorial_gpio_design.png|center|frame|GPIO Design]]
 +
|}
 +
 
 +
== Coding ==
 
=== Hardware Registers ===
 
=== Hardware Registers ===
 
The hardware registers map to physical pins.  If we want to attach our switch and the LED to our microcontroller's PORT0, then here are the relevant registers and their functionality :
 
The hardware registers map to physical pins.  If we want to attach our switch and the LED to our microcontroller's PORT0, then here are the relevant registers and their functionality :
Line 32: Line 50:
 
|}
 
|}
  
 +
<BR/>
 
=== Switch ===
 
=== Switch ===
 
{| class="wikitable"
 
{| class="wikitable"
Line 57: Line 76:
  
 
=== LED ===
 
=== LED ===
We will interface our LED to PORT0.3, or port zero's 4th pin (counting from 0).
 
 
==== Hardware ====
 
 
{| class="wikitable"
 
{| class="wikitable"
 +
|+ We will interface our LED to PORT0.3, or port zero's 4th pin (counting from 0).
 
|-
 
|-
|[[File:gpio_led_active_low.png|center|frame|Active-low LED circuit]]
+
|
|[[File:gpio_led_active_high.png|center|frame|Active-high LED circuit]]
 
|}
 
 
 
==== Software ====
 
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
 
/* Make direction of PORT0.3 as OUTPUT */
 
/* Make direction of PORT0.3 as OUTPUT */
Line 82: Line 95:
 
LPC_GPIO0->FIOCLR = (1 << 3);
 
LPC_GPIO0->FIOCLR = (1 << 3);
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
|Given below are two configurations of an LED.  Usually, the "sink" current is higher than "source", hence the active-low configuration is used more often.
 +
[[File:gpio_led_active_low.png|center|frame|Active-low LED circuit]] [[File:gpio_led_active_high.png|center|frame|Active-high LED circuit]]
 +
|}
 +
 +
== Assignment ==
 +
At the end of this lab, you should be familiar with how a microcontroller's memory can access physical pins.  Test your knowledge by doing the following:
 +
*  Interface your board's GPIO pin to an external switch
 +
*  Interface your board's GPIO pin to an LED
 +
*  If the switch is pressed, light up an LED
 +
*  Do not use any pre-existing library such as a GPIO class
 +
 +
Upload into the textbox just the relevant code, probably just main.cpp
 +
 +
<b>Extra Credit:</b> Do something creative, such as lighting up an LED based on a terminal command.
 +
 +
[[Embedded System GPIO Assignment]]
  
== Conclusion ==
+
-->
At the end of this lab, you should be familiar with how a microcontroller's memory can access physical pins.
 

Latest revision as of 20:02, 25 January 2019

Socialledge is moving to two portals.

  • The Wiki will remain here for general references about the SJ-One board, and to document student reports.
  • The bookstack will now be used for SJSU assignments

This article has been moved here