You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
digitalRead (wiring_digital.c) only works when the pin is configured as an input, but should also work checking the state of an output pin.
Code
The following code will always return '0' (low) even though the GPIO pin is clearly being toggled:
#include <Arduino.h>
const int baudrate = 115200;
void setup() {
Serial.begin (baudrate);
pinMode(PIN_LED2, OUTPUT);
}
void loop() {
int val = 0;
digitalWrite(PIN_LED2, HIGH);
val = digitalRead(PIN_LED2);
Serial.println(val, HEX);
delay(500);
digitalWrite(PIN_LED2, LOW);
val = digitalRead(PIN_LED2);
Serial.println(val, HEX);
delay(500);
}
Issue
The nRF5x has separate NRF_GPIO->IN and NRF_GPIO->OUT registers. The current implementation of digitalRead assumes the pins is always configured as an input when we read it, but while this is true 95% of the time we should detect the pin mode and if it is an OUTPUT use the OUT register:
int digitalRead( uint32_t ulPin )
{
if (ulPin >= PINS_COUNT) {
return 0;
}
ulPin = g_ADigitalPinMap[ulPin];
return ((NRF_GPIO->IN >> ulPin) & 1UL) ? HIGH : LOW ;
}
The text was updated successfully, but these errors were encountered:
digitalRead
(wiring_digital.c) only works when the pin is configured as an input, but should also work checking the state of an output pin.Code
The following code will always return '0' (low) even though the GPIO pin is clearly being toggled:
Issue
The nRF5x has separate
NRF_GPIO->IN
andNRF_GPIO->OUT
registers. The current implementation ofdigitalRead
assumes the pins is always configured as an input when we read it, but while this is true 95% of the time we should detect the pin mode and if it is an OUTPUT use theOUT
register:The text was updated successfully, but these errors were encountered: