Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only one pin interrupt on nRF52840 devices #39

Closed
ohazi opened this issue Sep 1, 2019 · 3 comments
Closed

Only one pin interrupt on nRF52840 devices #39

ohazi opened this issue Sep 1, 2019 · 3 comments

Comments

@ohazi
Copy link

ohazi commented Sep 1, 2019

Attaching interrupts for multiple pin change events via attachInterrupt(...) doesn't appear to work on the new nRF52840 based nano boards.

In the simplified test case below, the first call to attachInterrupt appears to work (falling edge of IN3, or pin 6). The other ones don't work. You can change the order of the attachInterrupt calls to get a different pin change interrupt to start working, but I've only ever seen one interrupt working at a time.

I think pins 4, 5, and 6 are actually pins P1_15, P1_13, and P1_14 on the nRF52840 (from variant.cpp), although this could be wrong (the documentation for these new nano boards is pretty lacking). Could this be because all of the inputs are on the same port? This normally isn't a restriction, e.g. when using Nordic's SDK, although I haven't used mbed on a Nordic IC.

In any case, this seems like a bug.

#define IN1 4
#define IN2 5
#define IN3 6

// LEDs
#define OUT1  22
#define OUT2  23
#define OUT3  24

int out1 = 1;
int out2 = 1;
int out3 = 0;

void in1_handler() {
  out1 = (out1 + 1) % 2;
  digitalWrite(OUT1, out1);
}

void in2_handler() {
  out2 = (out2 + 1) % 2;
  digitalWrite(OUT2, out2);
}

void in3_handler() {
  out3 = (out3 + 1) % 2;
  digitalWrite(OUT3, out3);
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while(!Serial) {}
  Serial.println("setup");

  digitalWrite(OUT1, out1);
  digitalWrite(OUT2, out2);
  digitalWrite(OUT3, out3);

  pinMode(OUT1, OUTPUT);
  pinMode(OUT2, OUTPUT);
  pinMode(OUT3, OUTPUT);

  pinMode(IN1, INPUT_PULLUP);
  pinMode(IN2, INPUT_PULLUP);
  pinMode(IN3, INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(IN3), in3_handler, FALLING);
  attachInterrupt(digitalPinToInterrupt(IN2), in2_handler, FALLING);
  attachInterrupt(digitalPinToInterrupt(IN1), in1_handler, FALLING);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("delay");
  delay(500);
}
@ohazi
Copy link
Author

ohazi commented Sep 1, 2019

@ohazi
Copy link
Author

ohazi commented Sep 1, 2019

ARMmbed/mbed-os#10949

@sandeepmistry
Copy link
Contributor

Closing this in favour of arduino/ArduinoCore-nRF528x-mbedos#7, which is the correct place for the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants