External interrupt on any pin ?

Hi, French newbie here.

I develop my own SAM3X8E based card with the arduino IDE, no issues with hardware.
I have done a lot of research without finding a solution that works. The documentation says that you can do an external interrupt with any pin. I can't seem to figure out how to do this when using an unmapped pin. attachInterrupt doesn't work in this case, I tried enableInterrup library, it's the same. If anyone can help me, I will appreciate it a lot. thank you in advance.

What do you call un unmapped pin ?

Hi, thanks for replies.
AttachInterrupt doesn't work with any pin. Just with IDE recognize pin. I'm not able to find a global method...

AFAIK attachinterrupt() works fine with any pin.

This sketch shows how attachinterrupt() works by simulating an input 125 KHz pulse provided by an internal Timer Counter (Connect a jumper between pin 2 and pin 11):

void ISR1() {
  static uint32_t Count;
  Count++;

  if (Count > 125000) {
    Count = 0;
    PIOB->PIO_ODSR ^= PIO_ODSR_P27;   // Toggle LED with a 1 Hz frequency
  }
}

void setup() {
  /*************  Timer Counter 0 Channel 0 to generate PWM pulses thru TIOA0  ************/
  PMC->PMC_PCER0 |= PMC_PCER0_PID27;                      // TC0 power ON - Timer Counter 0 channel 0 IS TC0

  PIOB->PIO_PDR |= PIO_PDR_P25;
  PIOB->PIO_ABSR |= PIO_ABSR_P25;

  TC0->TC_CHANNEL[0].TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1  // MCK/2, clk on rising edge
                              | TC_CMR_WAVE               // Waveform mode
                              | TC_CMR_WAVSEL_UP_RC        // UP mode with automatic trigger on RC Compare
                              | TC_CMR_ACPA_CLEAR          // Clear TIOA0 on RA compare match
                              | TC_CMR_ACPC_SET;           // Set TIOA0 on RC compare match

  TC0->TC_CHANNEL[0].TC_RC = 336;  //<*********************  Frequency = (Mck/2)/TC_RC  Hz = 125 KHz
  TC0->TC_CHANNEL[0].TC_RA = 10;  //<********************   Duty cycle = (TC_RA/TC_RC) * 100  %

  TC0->TC_CHANNEL[0].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN; // Software trigger TC0 counter and enable
  /***************************************************************************************/

  pinMode(LED_BUILTIN, OUTPUT);
  attachInterrupt(11, ISR1, RISING);
}

void loop() {

}
thanks for the example.
But i still haven't figured out how to declare some pins with attachInterrupt.
e.g. for port B, how to declare PB0 to PB11 in attachInterrupt ?
I can't find digital pin name for this...

First, create a new “variant” that gives the pins you want to use arduino-style pin names.
(Ie make a map for all the pins you are using)

You read the answer directly in Graynomad pinout diagram. E.g. pin 2 = PB25, pin 11 = PD7.

Exactly, but nothing for pin PB0 to PB11 in Graynomad !!! This is my problem...

I just saw that in my arduino / hardware installation I have nothing concerning the sam series. Is it normal ?
I can't find variants files for due or others...

Some Sam3x pins are not broken out on a DUE, hence you won't find them in the Pinout diagram.

2 possible workarounds:

1/ As stated in reply #5, alter the variant file. This file is located at:

.../packages/arduino/hardware/sam/1.6.x/Variants that you can easily find on your PC by clicking in the URL at the bottom of the window opened after selecting File/Preferences in an IDE window (C:\Users\xxx\AppData\Local\Arduino15\preference.txt)

2/ Program your own code to detect an external interrupt. It's a bit more complex but external interrupts can be processed much faster than with the arduino function attachInterrupt().

I found it here :
AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x

I'm searching now for method/example . Thanks.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.