GPIO Peripheral Interrupts
GPIO Peripheral Interrupts
Interrupts
1
2303ENG Embedded Systems(NA and GC)
Enabling interrupts:
System level
(via NVIC Registers) PortB
PortD
e.g. Uart0
Peripheral level
(via GPIO Registers) PortB Pin2
Connected to
Connected to terminal
Connected to light switch
key press
motion sensor
Interrupt Enable / Disable (CPU level)
Embedded C
//DisableInterrupts:
asm("CPSID I") ;
//EnableInterrupts:
asm("CPSIE I");
//EnableInterrupts:
__enable_irq();
External Interrupts
Eg: Triggered by GPIO pin, UART etc.
GPIO registers (datasheet, p636)
UART Registers (datasheet, p862)
GPIO Interrupts
| pins 7-0
Where x is A, B, … , Q
GPIO pin interrupt: Level sensitive
| pins 7-0
GPIO_IEV is used to set the type of trigger event, based on whether edge or level
trigger is selected in register GPIO_IS.
Where x is A, B, … , Q
GPIO pin interrupt : Edge sensitive
| pins 7-0
For edge sensitive
GPIO_IEV and GPIO_IBE together set the edge interrupt for the GPIO pin to be :
⚫ falling edge triggered ( 3.3V→0V) IBE IEV Edge interrupt
⚫ rising edge triggered ( 0V→3.3V ) , or 0 0 Falling ( )
⚫ both ( & )
0 1 Rising ( )
Where x is A, B, … , Q
GPIO pin interrupt : Putting it all together
0 0 1 Rising ( )
0 1 0 Both ( & )
0 1 1 Both ( & )
1 0 0 Low Level
1 0 1 High Level
EG: Hi Level trigger on pin 5
| pins 7-0
Where X is A, B, C, D, E, F
GPIO Interrupt configuration:
| pins 7-0
Raw Status register - a bit is set in this register when an interrupt condition occurs
on the corresponding GPIO pin.
This is read only register.
If bit set (=1) in GPIO_ICR (interrupt clear) register, the corresponding bit in the
GPIO_RIS register is cleared.
Bit value:
0 = Interrupt condition has not occurred on corresponding pin.
1 = Interrupt condition has occurred on corresponding pin.
Where x is A, B, … , Q
GPIO Masked Interrupt Status
| pins 7-0
Masked Status register - a bit is set in this register when an event has triggered an
interrupt to the interrupt controller. Thus both an event has occurred, and an
interrupt on this pin is enabled.
This is read only register.
If bit set (=1) in GPIO_ICR (interrupt clear) register, the corresponding bit in the
GPIO_MIS register is also cleared.
Bit value:
0 = Interrupt condition has not occurred on corresponding pin or is masked.
1 = Interrupt condition has occurred on corresponding pin and triggered an
interrupt to interrupt controller.
Where x is A, B, … , Q
GPIO Interrupt Clear
| pins 7-0
Writing a 1 to bit clears the corresponding interrupt status bits in GPIOx->RIS and
GPIOx->MIS registers. (Writing a 0 does nothing.)
Where x is A, B, … , Q
EG: How clear interrupt event on pins 6,5?
4. Set NVIC to enable interrupts for port using designated interrupt number
(NVIC->ENn, NVIC->PRIn)