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.
11 years, 1 month ago.
FRDM KL25Z InterruptIn
Hi, How can i use InterruptIn on FRDM KL25Z?
Here is my not working code
- include "mbed.h" InterruptIn event(PTB8); DigitalOut lamp1(PTB9);
void trigger() { lamp1=!lamp1; } int main() {
event.rise(&trigger);
}
3 Answers
11 years, 1 month ago.
Hi,
Please use the <<code>>
<</code>> when you want to post source code.
Can you try to put a while(1); at the end of your main function to avoid that main ends its execution:
#include "mbed.h" InterruptIn event(PTB8); DigitalOut lamp1(PTB9); void trigger() { lamp1=!lamp1; } int main() { event.rise(&trigger); while(1); }
Hi, Sam...
If I use your code, I get a flashing red light. In fact, without checking every pin, I get a flashing red light EXCEPT for the PTD block and at least one from PTA. Many in PTB and PTC cause red flashing. Merely creating an InterruptIn variable using PTB8 causes the flashing. Here's my code:
#include "mbed.h" //InterruptIn sBlue(PTD7); // works; or at least doesn't cause red flashing InterruptIn sBlue(PTB8); // causes red LED flashing DigitalOut myled(LED_BLUE); int main() { while(1) { myled = 1; wait(0.2); myled = 0; wait(0.2); } }
Any thoughts?
posted by 11 Mar 201311 years, 1 month ago.
Quote:
I get a flashing red light EXCEPT for the PTD block and at least one from PTA
This is the intended behavior: only those ports trigger interrupt requests: cmsis/KL25Z/MKL25Z4.h
PORTA_IRQn = 30, /**< Port A interrupt */ PORTD_IRQn = 31 /**< Port D interrupt */ } IRQn_Type;
You can see the code triggering the error here: capi/gpio_irq_api.c
uint32_t ch_base, vector; IRQn_Type irq_n; switch (obj->port) { case PortA: ch_base = 0; irq_n = PORTA_IRQn; vector = (uint32_t)gpio_irqA; break; case PortD: ch_base = 32; irq_n = PORTD_IRQn; vector = (uint32_t)gpio_irqD; break; default: error("gpio_irq only supported on port A and D\n"); break; }
HTH, Emilio
Thanks, Emilio, it does help. However, from the InterruptIn page:
<<quote>>Any of the numbered mbed pins can be used as an InterruptIn, except p19 and p20.<</quote>>
Could we get this page updated? It would've saved me a bit of time. The error message on line 13 would've helped, too, but I don't often connect to USBTX/RX to check console output. However, if I get a flashing light, again, that'll be my first debugging step. Thanks!
posted by 12 Mar 201311 years, 1 month ago.
Hi all, Thank you very much. Now it is working :), i use now PTD6 and not PTB8. As you said "gpio_irq only supported on port A and D". Thank you to all, Vilounha