Setting up external interrupts using the EXTINT library on SAMD21

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

Hey all,

 

I am using a SAMD21G18A. I have 3 buttons that are currently connected to pins PA15, PA06, and PA07. I want to use external interrupts to detect when those buttons are pressed.

 

I was taking a look at ASF example project ("EXTINT_QUICK_START_CALLBACK"), which is meant for the SAMD21 Xplained Pro (which uses a SAMD21J18A), and I am finding their setup code a bit confusing. Here is their setup code:

 

void configure_extint_channel(void)
{
	struct extint_chan_conf config_extint_chan;
	extint_chan_get_config_defaults(&config_extint_chan);

	config_extint_chan.gpio_pin           = BUTTON_0_EIC_PIN;
	config_extint_chan.gpio_pin_mux       = BUTTON_0_EIC_MUX;
	config_extint_chan.gpio_pin_pull      = EXTINT_PULL_UP;
	config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;

	extint_chan_set_config(BUTTON_0_EIC_LINE, &config_extint_chan);
}

void configure_extint_callbacks(void)
{
	extint_register_callback(extint_detection_callback, BUTTON_0_EIC_LINE, EXTINT_CALLBACK_TYPE_DETECT);
	extint_chan_enable_callback(BUTTON_0_EIC_LINE, EXTINT_CALLBACK_TYPE_DETECT);
}

Can anyone tell me why there are separate definitions for BUTTON_0_EIC_PINBUTTON_0_EIC_LINE, and BUTTON_0_EIC_MUX? And why is a mux even involved here? I simply want to attach a pin to an interrupt - that's it. I'm not sure why a mux is involved, nor am I sure what mux this is referring to, and I'm not sure what "line" (in BUTTON_0_EIC_LINE) even references here.

 

Thanks for any help you can provide!

 

[edit]

 

The values for BUTTON_0_EIC_PIN and BUTTON_0_EIC_LINE are both 15 (which is the pin number on the SAMD21 Xplained Pro, so why have 2 definitions? what does "LINE" even refer to???)

The value for BUTTON_0_EIC_MUX is 0 (why does this definition even exist? what is it for? why is a mux involved here at all???)

 

[/edit]

 

 

Last Edited: Wed. Mar 17, 2021 - 03:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The "LINE" is the external interrupt number of the EIC. Yes, it happens to be the PIN number in this case, but they mean different things. PA15 happens to be on EXTINT LINE 15, the External Interrupt 15.

There are several external interrupts on the SAMD21 and they each can only be attached to their respective PIN. Interrupt line 15 is for PA15.

While I'm not entirely sure about why it needs a MUX, I figure it's because it needs to detect high/low state changes, using the MUX for that purpose.

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

Check "I/O Multiplexing and Considerations", the EIC is MUX function A (so the value 0 will be set in  PMUXn.PMUXE/O in the PORT, B=1, C=2 etc).

Probably the original definition of BUTTON_0_EIC_MUX is not 0 but another definition like MUX_PA15A_EIC_EXTINT15 which makes more sense when looking at the table in "I/O Multiplexing and Considerations", i.e., it is function A for PA15 and this is the EIC EXTINT[15].

/Lars