i using arduio due , programing atmel studio 6.2. have had huge learning curve using ide , atmel asf. nothing straightforward in arduino ide. none less, want toggle led on , off simple interrupt on pull-up configured tactile button. code:
then interrupt routine:
things work normal , expected until 18 seconds in. after 18 seconds, led turns off if on. tested setting led 2 high default , removing interrupt together:
pio_set_output(pioc, blue_led2, high, disable, enable);
in case, led stay on forever, every 18 seconds, led flash off on once quickly. why happening?
code: [select]
#include <asf.h>
#include "pio.h"
// define led pins
#define blue_led2 pio_pc28 // arduino due pin 3
#define blue_led3 pio_pc26 // arduino due pin 4
#define blue_led4 pio_pc25 // arduino due pin 5
#define blue_led5 pio_pc24 // arduino due pin 6
#define blue_led6 pio_pc23 // arduino due pin 7
// define button pins
#define button_1 pio_pc22
#define button_2 pio_pc21
// define function prototype button interrupt
void button_press_handler(uint32_t, uint32_t);
void toggle_led(uint32_t);
int main (void)
{
/* initialize sam system. */
sysclk_init();
// initialize input/out
ioport_init();
pmc_enable_periph_clk(id_pioc);
pmc_enable_periph_clk(id_piob);
// set led pins outputs , set there default values (off)
pio_set_output(pioc, blue_led2, low, disable, enable);
pio_set_output(pioc, blue_led3, low, disable, enable);
pio_set_output(pioc, blue_led4, low, disable, enable);
pio_set_output(pioc, blue_led5, low, disable, enable);
pio_set_output(pioc, blue_led6, low, disable, enable);
// set button pins pull-up inputs
pio_set_input(pioc, button_1, pio_pullup);
pio_set_input(pioc, button_2, pio_pullup);
// configure button input pin interrupt mode , handler (falling edge)
pio_handler_set(pioc, id_pioc, button_1, pio_it_rise_edge, button_press_handler);
pio_handler_set(pioc, id_pioc, button_2, pio_it_rise_edge, button_press_handler);
// enable interrupts
pio_enable_interrupt(pioc, button_1);
pio_enable_interrupt(pioc, button_2);
nvic_enableirq(pioc_irqn);
while(1){
// doing stuff in here...
}
}
then interrupt routine:
code: [select]
// interrupt handler button press
void button_press_handler(uint32_t a, uint32_t b)
{
// turn led's on or off
toggle_led(blue_led2);
toggle_led(blue_led3);
toggle_led(blue_led4);
toggle_led(blue_led5);
toggle_led(blue_led6);
}
// function toggle led on/off
void toggle_led(uint32_t led){
if (pio_get(pioc, pio_type_pio_output_0, led))
pio_clear(pioc, led);
else
pio_set(pioc, led);
}
things work normal , expected until 18 seconds in. after 18 seconds, led turns off if on. tested setting led 2 high default , removing interrupt together:
pio_set_output(pioc, blue_led2, high, disable, enable);
in case, led stay on forever, every 18 seconds, led flash off on once quickly. why happening?
anyone?
Arduino Forum > Using Arduino > Programming Questions > LED turns off auomatically after about 18 seconds on its own? - Arduino Due
arduino
Comments
Post a Comment