interrupts, ItsyBitsy nRF52840 Express

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
laddhe
 
Posts: 16
Joined: Wed Sep 27, 2017 10:37 am

interrupts, ItsyBitsy nRF52840 Express

Post by laddhe »

The posted description for this board includes "All pins can be interrupt inputs - nRF52840 will assign an IRQ to any pin you like. I am struggling to prove that. It would be very important. What is wrong with the following Arduino code? It seems to prove that not a single interrupt works.

Code: Select all

===========================================
// This is the Interrupt test, using LED output of ItsyBitsy.
// Make sure "Get board info" shows: "Adafruit ItsyBitsy nRF52840 Express"

#include <bluefruit.h>

// AdaFruit board numbers for pins to be grounded momentarily by switches
// There is an external pullup resistor on each pin.
int pin0 = 13;
int pin1 = 12;
int pin2 = 11;
int pin3 = 10;
int pin4 = 9;
int pin5 = 7;
int pin6 = A2;
int pin7 = A4;

unsigned long Act = 0;
volatile unsigned char ksw;

void flash(byte times, unsigned long on,  unsigned long off) {
    while (times > 0) {
       digitalWrite(LED_BUILTIN, HIGH);
       delay(on);
       digitalWrite(LED_BUILTIN, LOW);
       delay(off);
       times--;
    }
    delay(5000);
}

// Interrupt Service Routines
void Cntc_0() {ksw = 0;}

void Cntc_1() {ksw = 1;}

void Cntc_2() {ksw = 2;}

void Cntc_3() {ksw = 3;}

void Cntc_4() {ksw = 4;}

void Cntc_5() {ksw = 5;}

void Cntc_6() {ksw = 6;}

void Cntc_7() {ksw = 7;}

void setup(void) {
  pinMode(pin0, INPUT);
  pinMode(pin1, INPUT);
  pinMode(pin2, INPUT);
  pinMode(pin3, INPUT);
  pinMode(pin4, INPUT);
  pinMode(pin5, INPUT);
  pinMode(pin6, INPUT);
  pinMode(pin7, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);

  attachInterrupt(digitalPinToInterrupt(13),Cntc_0,LOW);
  attachInterrupt(digitalPinToInterrupt(12),Cntc_1,LOW);
  attachInterrupt(digitalPinToInterrupt(11),Cntc_2,LOW);
  attachInterrupt(digitalPinToInterrupt(10),Cntc_3,LOW);
  attachInterrupt(digitalPinToInterrupt(9), Cntc_4,LOW);
  attachInterrupt(digitalPinToInterrupt(7), Cntc_5,LOW);
  attachInterrupt(digitalPinToInterrupt(A2),Cntc_6,LOW);
  attachInterrupt(digitalPinToInterrupt(A4),Cntc_7,LOW);

  Act = 0;
  ksw = 8;
}

void loop() {
   if(++Act > 1000) {
      Act = 0;
      flash(3,200,200);
   }
   if(ksw != 8) { // an intrrupted happened
      ksw = 8;
      Act = 0;
      flash(5,5000,5000);
  }
}
Last edited by adafruit_support_mike on Mon Sep 19, 2022 10:48 pm, edited 1 time in total.
Reason: added CODE tags

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: interrupts, ItsyBitsy nRF52840 Express

Post by adafruit_support_mike »

The first thing I notice is that your digitalPinToInterrupt() calls don't match your pinMode() calls.

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”