Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 6 months ago.
How to detect both rise and fall state seperately of a pin with Interrupt?
I would like to port a SDI-12 protocol code from arduino to mbed for my SDI-12 based sensor, since i could not find a basic code or library for mbed. For this aim:
Is it possible to define two different functions for rise and fall edges of a pin?
For example;
DigitalIn pulse(PB_2); InterruptIn pulse_interrupt(PB_2); pulse_interrupt.fall(&pulse_fall_isr); pulse_interrupt.rise(&pulse_rise_isr);
Thanks...
1 Answer
8 years, 6 months ago.
Yes, I believe so please see example below, Regards etc.,
#include "mbed.h" DigitalOut RED(D6); DigitalOut GRN(D5); DigitalOut AMB(D4); DigitalOut myled(LED1); InterruptIn pulse(D8); //Pulse Monitoring Line Ticker timer; void red() {RED=1;GRN=0;} //Rising Edge Detected void grn() {RED=0;GRN=1;} //Falling Edge Detected void amb() {AMB=!AMB;} //Blinking LED for Ticker Interrupt int main(){ timer.attach(&amb,1); //Service Ticker Interrupt pointer &NAME in 1 second intervals pulse.rise(&red); //Service RISING EDGE Interrupt to pointer &NAME pulse.fall(&grn); //Service FALLING EDGE Interrupt to pointer &NAME while(1){ sleep(); //Sleep to save power, Interrupted by Ticker and Pulse events } }
According to this link it is possible...
https://developer.mbed.org/questions/54957/InterruptIn-on-pin-change-on-Nucleo-F401/
Can you confirm it please again?
posted by Kamil M 26 Apr 2016