Configuring External Interrupt

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've a SAMD20J18 explained pro eval board, and I am trying to use an IO pin to toggle the led on it using external interrupts.  I've read the datasheet and looked at examples, but it does not seem to work.

 

Code below

#include <atmel_start.h>

#define LED       GPIO(GPIO_PORTA, 14)       /*!< GPIO pin used as field LED                        */

volatile bool flag   = false;

void config_gpio(int pin)
{
    gpio_set_pin_direction(pin, GPIO_DIRECTION_OUT);
    gpio_set_pin_level(pin,    false);
    gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_OFF);
}

static void myTestCallBack(void)
{
    flag = !flag;
}    

int main(void)
{
    system_init();  
    config_gpio(LED);
       
    ext_irq_register(PIN_PB00, myTestCallBack );
    ext_irq_enable(PIN_PB00); 

    while (1) {
            gpio_set_pin_level(LED,flag);
            delay_ms( 250 ) ;      
    }
}

I've checked that the pin is being toggled correctly by using it to drive the led correctly, but figure there is something not being initialized.

 

The project is set up using Atmel start project wizard, the driver init code is;

/*
 * Code generated from Atmel Start.
 *
 * This file will be overwritten when reconfiguring your Atmel Start project.
 * Please copy examples or other code you want to keep to a separate file
 * to avoid losing it when reconfiguring.
 */

#include "driver_init.h"
#include <peripheral_clk_config.h>
#include <utils.h>
#include <hal_init.h>
#include <hpl_gclk_base.h>
#include <hpl_pm_base.h>

void EXTERNAL_IRQ_0_init(void)
{
	_gclk_enable_channel(EIC_GCLK_ID, CONF_GCLK_EIC_SRC);

	// Set pin direction to input
	gpio_set_pin_direction(PB00, GPIO_DIRECTION_IN);

	gpio_set_pin_pull_mode(PB00,GPIO_PULL_DOWN);

	gpio_set_pin_function(PB00, PINMUX_PB00A_EIC_EXTINT0);

	ext_irq_init();
}

void system_init(void)
{
	init_mcu();

	EXTERNAL_IRQ_0_init();
}

Currently trying to search out what is not configured correctly, can anyone sew why won't this work?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Same here, any help?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try adjusting EXT_IRQ_AMOUNT in hal_ext_irq.c

Mine was too low and so some interrupts would not be registered.