(22 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[category: LPC1768 Tutorials]]
 
[[category: LPC1768 Tutorials]]
  
=Objective:=
 
 
In this tutorial we will discuss how to configure and use the LPC1768 external interrupts(EINT0-EINT3).<br>
 
In this tutorial we will discuss how to configure and use the LPC1768 external interrupts(EINT0-EINT3).<br>
At the end of tutorial we will see how to use the exploreembedded external interrupt library.
+
At the end of tutorial we will see how to use the ExploreEmbedded external interrupt library.
 
<br><br><br><br>
 
<br><br><br><br>
  
Line 24: Line 23:
 
<br><br>
 
<br><br>
  
 +
[[FILE:Lpc1768_external_interrupts.png]]
  
 
=EINT Registers=
 
=EINT Registers=
Below table shows the registers associated with LPC1768 external interrupts. LPC1768 interrupts can be configured as edge/level triggered.
+
Below table shows the registers associated with LPC1768 external interrupts.
 
{| class="table table-striped table-hover table-condensed table-bordered"
 
{| class="table table-striped table-hover table-condensed table-bordered"
 
|-class="info"
 
|-class="info"
Line 38: Line 38:
 
|-
 
|-
 
|EXTPOLAR|| External Interrupt Polarity(Falling/Rising Edge, Active Low/High)
 
|EXTPOLAR|| External Interrupt Polarity(Falling/Rising Edge, Active Low/High)
 +
|}<br>
 +
 +
 +
{| class="table table-striped table-hover table-condensed table-bordered"
 +
|-class="info"
 +
|EXTINT
 +
|-
 +
|31:4 || 3 || 2 || 1 || 0 
 +
|-
 +
|RESERVED|| EINT3 || EINT2  || EINT1 || EINT0
 
|}
 
|}
 +
<b>EINTx:</b> Bits will be set whenever the interrupt is detected on the particular interrupt pin.<br>
 +
If the interrupts are enabled then the control goes to ISR.<br>
 +
Writing one to specific bit will clear the corresponding interrupt.
 
<br><br>
 
<br><br>
 +
 +
 +
{| class="table table-striped table-hover table-condensed table-bordered"
 +
|-class="info"
 +
|EXTMODE
 +
|-
 +
|31:4 || 3 || 2 || 1 || 0 
 +
|-
 +
|RESERVED|| EXTMODE3 || EXTMODE2  || EXTMODE1 || EXTMODE0
 +
|}
 +
<b>EXTMODEx:</b> This bits is used to select whether the EINTx pin is level or edge Triggered<br>
 +
0: EINTx is Level Triggered.<br>
 +
1: EINTx is Edge Triggered.
 +
<br><br>
 +
 +
 +
{| class="table table-striped table-hover table-condensed table-bordered"
 +
|-class="info"
 +
|EXTPOLAR
 +
|-
 +
|31:4 || 3 || 2 || 1 || 0 
 +
|-
 +
|RESERVED|| EXTPOLAR3 || EXTPOLAR2  || EXTPOLAR1 || EXTPOLAR0
 +
|}
 +
<b>EXTPOLARx:</b> This bits is used to select polarity(LOW/HIGH, FALLING/RISING) of the EINTx interrupt depending on the EXTMODE register.<br>
 +
0: EINTx is Active Low or Falling Edge (depending on EXTMODEx).<br>
 +
1: EINTx is Active High or Rising Edge (depending on EXTMODEx).<br>
 +
<br><br><br>
 +
 +
=Steps to Configure Interrupts=
 +
#Configure the pins as external interrupts in PINSELx register.
 +
#Clear any pending interrupts in EXTINT.
 +
#Configure the EINTx as Edge/Level triggered in EXTMODE register.
 +
#Select the polarity(Falling/Rising Edge, Active Low/High) of the interrupt in EXTPOLAR register.
 +
#Finally enable the interrputs by calling NVIC_EnableIRQ() with IRQ number.
 +
<br><br>
 +
 +
=Code=
 +
Below example shows the toggling of Leds depending on the external interrupts.
 +
<html>
 +
<script src="https://gist.github.com/SaheblalBagwan/dc02144bfe786cc4169100cda17245d5.js"></script>
 +
</html>
 +
<br><br>
 +
 +
=Using ExploreEmbedded Libraries=
 +
In the above tutorial we discussed how to configure and use the LPC1768 external interrupts.<br>
 +
Now we will see how to use the ExploreEmbededd external interrupt libraries.
 +
<html>
 +
<script src="https://gist.github.com/SaheblalBagwan/ee07ec3913b23f580a651c5f33dcd3af.js"></script>
 +
</html>
 +
<br><br>
 +
 +
 +
 +
The below example demonstrates the difference between the edge triggered and level triggered interrupt.<br>
 +
EINT0 is configured as FALLING edge and counter will be incremented whenever there is a high-low pulse on EINT0. <br>
 +
EINT1 is configured as ACTIVE low and counter will be inctermented as long as EINT1 is LOW.<br>
 +
EINT1 counter increments fast as the ISR will be executed multiple times.
 +
<html>
 +
<script src="https://gist.github.com/SaheblalBagwan/1ea1ac239d0136661b81015decefc756.js"></script>
 +
</html>
 +
<br><br>
 +
 +
 +
= Downloads=
 +
Download the complete project folder from the below link:
 +
https://codeload.github.com/ExploreEmbedded/Explore-Cortex-M3-LPC1768-Stick-DVB-14001/zip/master<br><br><br><br>
 +
 
 +
Have a opinion, suggestion , question or feedback about the article let it out here!
 +
{{DISQUS}}

Latest revision as of 17:29, 29 April 2016


In this tutorial we will discuss how to configure and use the LPC1768 external interrupts(EINT0-EINT3).
At the end of tutorial we will see how to use the ExploreEmbedded external interrupt library.



EINTx Pins

LPC1768 has four external interrupts EINT0-EINT3.
As LPC1768 pins are multi functional, these four interrupts are available on multiple pins.
Below table shows mapping of EINTx pins.

Port Pin PINSEL_FUNC_0 PINSEL_FUNC_1 PINSEL_FUNC_2 PINSEL_FUNC_3
P2.10 GPIO EINT0 NMI
P2.11 GPIO EINT1 I2STX_CLK
P2_12 GPIO EINT2 I2STX_WS
P2.13 GPIO EINT3 I2STX_SDA



Lpc1768 external interrupts.png

EINT Registers

Below table shows the registers associated with LPC1768 external interrupts.

Register Description
PINSELx To configure the pins as External Interrupts
EXTINT External Interrupt Flag Register contains interrupt flags for EINT0,EINT1, EINT2 & EINT3.
EXTMODE External Interrupt Mode register(Level/Edge Triggered)
EXTPOLAR External Interrupt Polarity(Falling/Rising Edge, Active Low/High)


EXTINT
31:4 3 2 1 0
RESERVED EINT3 EINT2 EINT1 EINT0

EINTx: Bits will be set whenever the interrupt is detected on the particular interrupt pin.
If the interrupts are enabled then the control goes to ISR.
Writing one to specific bit will clear the corresponding interrupt.


EXTMODE
31:4 3 2 1 0
RESERVED EXTMODE3 EXTMODE2 EXTMODE1 EXTMODE0

EXTMODEx: This bits is used to select whether the EINTx pin is level or edge Triggered
0: EINTx is Level Triggered.
1: EINTx is Edge Triggered.


EXTPOLAR
31:4 3 2 1 0
RESERVED EXTPOLAR3 EXTPOLAR2 EXTPOLAR1 EXTPOLAR0

EXTPOLARx: This bits is used to select polarity(LOW/HIGH, FALLING/RISING) of the EINTx interrupt depending on the EXTMODE register.
0: EINTx is Active Low or Falling Edge (depending on EXTMODEx).
1: EINTx is Active High or Rising Edge (depending on EXTMODEx).



Steps to Configure Interrupts

  1. Configure the pins as external interrupts in PINSELx register.
  2. Clear any pending interrupts in EXTINT.
  3. Configure the EINTx as Edge/Level triggered in EXTMODE register.
  4. Select the polarity(Falling/Rising Edge, Active Low/High) of the interrupt in EXTPOLAR register.
  5. Finally enable the interrputs by calling NVIC_EnableIRQ() with IRQ number.



Code

Below example shows the toggling of Leds depending on the external interrupts.

Using ExploreEmbedded Libraries

In the above tutorial we discussed how to configure and use the LPC1768 external interrupts.
Now we will see how to use the ExploreEmbededd external interrupt libraries.


The below example demonstrates the difference between the edge triggered and level triggered interrupt.
EINT0 is configured as FALLING edge and counter will be incremented whenever there is a high-low pulse on EINT0.
EINT1 is configured as ACTIVE low and counter will be inctermented as long as EINT1 is LOW.
EINT1 counter increments fast as the ISR will be executed multiple times.


Downloads

Download the complete project folder from the below link: https://codeload.github.com/ExploreEmbedded/Explore-Cortex-M3-LPC1768-Stick-DVB-14001/zip/master



Have a opinion, suggestion , question or feedback about the article let it out here!