energia / msp432-core

MSP432 Core and Framework
14 stars 10 forks source link

MSP432 — digitalRead() in ISR not working #10

Closed robertinant closed 7 years ago

robertinant commented 7 years ago

From @JasonParmenter on April 16, 2016 23:15

The code below demonstrates that the digitalRead() function does not work inside of an ISR.

const int encoder0PinA = 11;
const int encoder0PinB = 31;

volatile int pinACount = 0;
volatile int pinBCount = 0;

volatile bool Aflag = false;
volatile bool Bflag = false;

///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////   S E T U P   //////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
void setup(){

  Serial.begin(9600);
  Serial.println("COUNTER STARTING UP");

  pinMode(11,INPUT);
  pinMode(31,INPUT);
  attachInterrupt(encoder0PinA, doEncoderA, CHANGE); 
  attachInterrupt(encoder0PinB, doEncoderB, CHANGE);

}

///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////   L O O P   //////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
void loop(){

  // SANITY CHECK

  Serial.println(digitalRead(11));  // Here to see that the pin does change states 
  Serial.println(digitalRead(31));  // Here to see that the pin does change states

  Serial.print("A Flag: ");
  Serial.print(Aflag);         // I never see either of these get set to 1.
  Serial.print("  B Flag: ");
  Serial.println(Bflag);
 ;
  Serial.println();
  delay(500);

}

void doEncoderA(){

 Aflag = digitalRead(encoder0PinA);

}

void doEncoderB(){

 Bflag = digitalRead(encoder0PinB);

}

Copied from original issue: energia/Energia#873

robertinant commented 7 years ago

From @fmilburn3 on April 17, 2016 0:41

Note that Energia doesn't seem to process CHANGE properly when specified in the attachInterrupt() function either. See this thread: http://forum.43oh.com/topic/9553-msp432-digitalread-interrupt-not-working/?p=72155

robertinant commented 7 years ago

From @abecedarian01 on April 20, 2016 5:59

digitalRead() issue possibly related to issue #860?

robertinant commented 7 years ago

digitalRead() does work in an ISR. The issue is a result of CHANGE not implemented on MSP432. The MSP432 does not natively support interrupt on CHANGE and there is no emulated implementation for it on like there is for msp430. If attacheInterrupt() is called with CHANGE you will get FALLING. Hence a digitalRead() in the ISR will always result in a 0.