SAMD21 Extint - how to recognize the rise and fall

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I've set a SAMD21 PB00 pin as external interrupt EXTINT0 and I've configured the SENSE bits of EIC CONFIG0 reg to catch both rise and fall.

At the EIC Handler i'm toggling a LED accordingly.

Everything seems working fine but i was wondering if there is a way to recognize, inside the handler, when it's rise or fall event.

Below my code:

#include "sam.h"

int main(void)
{
    /* Initialize the SAM system */
    SystemInit();

	__disable_irq();

	PORT->Group[1].DIRSET.reg = PORT_PB00;
	PORT->Group[1].OUTCLR.reg = PORT_PB00;

	PORT->Group[0].PINCFG[16].reg |= (1 << 0) | (1 << 2); // Set the PMUXEN to enable alternative function and enable pull
	PORT->Group[0].PMUX[8].reg = 0; // Set Group A

	GCLK->CLKCTRL.reg |= (1 << 0) | (1 << 2) | (1 << 14); // Set the generic clock control to EIC and enable
	EIC->CTRL.reg = 1; // Software reset
	while(EIC->STATUS.reg  & 0x80){} // Wait for synch
	//EIC->CONFIG[0].reg |= (1 << 3); // Enable filter
	EIC->CONFIG[0].reg |= (1 << 0) | (1 << 1); //Set sense to RISE and FALL
	EIC->INTENSET.reg |= (1 << 0); // Enable EXTINT[0]
	EIC->CTRL.reg |= (1 << 1); // Enable EIC

	NVIC->ISER[0] |= (1 << 4);// Enable IRQ4 (EIC assigned IRQ in the Interrupt vector table)

	__enable_irq();

    while (1)
    {

    }
}

void EIC_Handler()
{
	if(EIC->INTFLAG.reg & 0x01)
	{
		PORT->Group[1].OUTTGL.reg = PORT_PB00;
		EIC->INTFLAG.reg = 1;
	}
}

Thanks in advance for any kind suggestion

Filo

Last Edited: Fri. Jul 14, 2017 - 04:04 PM