Skip to content

SPI.usingInterrupt block incorrect external pin interrupt #316

Closed
@ggajoch

Description

@ggajoch

Simple testcase (to run it you need to short pins 6 and 7)

#include <SPI.h>

void interrupt() {
  SerialUSB.println("but it is.");
}

void setup() {
  SerialUSB.begin(9600);
  
  pinMode(6, INPUT_PULLUP);
  pinMode(7, OUTPUT);
  digitalWrite(7, LOW);
  
  attachInterrupt(digitalPinToInterrupt(6), interrupt, RISING);
  
  SPI.usingInterrupt(digitalPinToInterrupt(6)); 

  SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
}

void loop() {
  SerialUSB.print("Interrupt should not be invoked... ");
  digitalWrite(7, HIGH);
  delay(1000);
  digitalWrite(7, LOW);
  delay(1000);
}

This bug origins in SPIClass::usingInterrupt(int interruptNumber) function, namely that digital pin number is not equivalent to SAMD interrupt number (in EIC module).

For example, for pin D6 proper interrupt to mask is EXTERNAL_INT_4.

I've submitted pull request with fix: #315

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions