energia / msp432-core

MSP432 Core and Framework
14 stars 10 forks source link

MSP432 issue with "digitalRead()" #11

Closed robertinant closed 8 years ago

robertinant commented 8 years ago

From @abecedarian01 on March 8, 2016 20:40

From 43oh.com topic: http://forum.43oh.com/topic/9426-digitalread-changes-the-state-of-the-pin/#entry71321

With the following code, setting the RED_LED pin "HIGH" then performing a read on the pin causes the pin to go LOW. If the pin is already LOW, the read does not cause it to go HIGH.

Paying close attention to the LED indicates the pin is going high as indicated by a very brief, weak flash of the LED.

int state = 0;

void setup() {  
  Serial.begin(115200);  
  pinMode(RED_LED, OUTPUT);
}

void loop() {
  digitalWrite(RED_LED, HIGH);
  state = digitalRead(RED_LED);
  Serial.print(state);
  delay(500);
  digitalWrite(RED_LED, LOW);
  state = digitalRead(RED_LED);
  Serial.println(state);
  delay(500); 
}

Copied from original issue: energia/Energia#860

robertinant commented 8 years ago

This behaves as designed. When doing a digitalRead() on a pin that has been set as OUTPUT with pinMode() the pin is turned into a INPUT.