InterruptIn - ピン変化割込み
InterruptIn - ピン変化割込み
Information
本ページは私家版のため、誤り等あればご指摘ください。
最新の情報は公式のドキュメントをご参照ください。
http://mbed.org/handbook/InterruptIn
I/Oピンの立上がり(Low->High)または立下り(High->Low)変化により割込みを発生します。

初期化
InterruptIn name(pin);
name: 名前(自由に決めて良い)
pin: ピン名(p19, p20以外)
立ち上がり割り込み
name.rise(fptr);
fptr: 割り込み処理関数のポインタ
Class中での利用
name.rise(&this, T::mptr);
立ち下がり割り込み
name.fall(fptr);
fptr: 割り込み処理関数のポインタ
Class中での利用
name.fall(&this, T::mptr);
プルアップ・プルダウン
name.mode(mode);
| mode | 備考 |
|---|---|
| PullUp | プルアップ |
| PullDown | プルダウン |
| PullNone | なし(フロート) |
例
p5へ接続されたスイッチからの割り込みでLEDを点滅させる
#include "mbed.h"
InterruptIn button(p5);
DigitalOut led(LED1);
DigitalOut flash(LED4);
void flip() {
led = !led;
}
int main() {
button.rise(&flip); // attach the address of the flip function to the rising edge
while(1) { // wait around, interrupts will interrupt this!
flash = !flash;
wait(0.25);
}
}
LPCXpresso コード
ピン変化割込み
P5(P0.9)立下りでLED(P1.18)点滅
#include "LPC17xx.h"
#ifdef __cplusplus
extern "C" {
void EINT3_IRQHandler ();
}
#endif
void EINT3_IRQHandler () {
static volatile int n = 0;
n ++;
if (n & 1) {
LPC_GPIO0->FIOSET = (1 << 22); // high
} else {
LPC_GPIO0->FIOCLR = (1 << 22); // low
}
LPC_GPIOINT->IO0IntClr |= (1 << 9); // clear flag
}
int main(void) {
LPC_PINCON->PINSEL1 &= ~(3 << 12); // GPIO (00)
LPC_GPIO0->FIODIR |= (1 << 22); // output
LPC_PINCON->PINSEL0 &= ~(3 << 18); // GPIO (00)
LPC_PINCON->PINMODE0 &= ~(2 << 18); // pull-up (00)
LPC_GPIO0->FIODIR &= ~(1 << 9); // input
NVIC_EnableIRQ(EINT3_IRQn);
LPC_GPIOINT->IO0IntEnF |= (1 << 9); // fall interrupt
__enable_irq();
while(1);
}
チャタリングに注意
タクトスイッチなどをつなぎ、割り込みで処理をさせる場合、スイッチのチャタリングを除去しておかないと、次の InterruptIn 割り込みが発生しなくなることがある。
簡単にはコンデンサでフィルタしてしまえばよい。
SW
___
+---o o---[100ohm]---+--- InterruptIn (mode=PullUp)
| |
GND---+--------||----------+
0.01uF
2 comments on InterruptIn - ピン変化割込み:
Please log in to post comments.

こんにちは。デバッグしていて気がつきました。 ×:rize ○:rise ですね。rizeだと「そんなメンバ無い」とエラーになります。