This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52 Digital Pin P0.20 issue

We are using this device and we seem to have an issue reading from P0.20.

I know this is a dual purpose pin. We have programmed it for input with pullup. We have it attached to switch that goes to ground. It always reads zero.

We had to use the following incantation to read 2 other inputs:

if ((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)){
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NRF_UICR->NFCPINS &= ~UICR_NFCPINS_PROTECT_Msk;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NVIC_SystemReset();
}

Is there a similar incantation for p0.20?

We are using the Arduino IDE, using Adafruit nRF52 feather as a design reference. We are using their firmware, and all else seems to be working.

The following is the Arduino code:

#define G_SWITCH_UP 19
#define G_SWITCH_DOWN 9
#define G_SWITCH_LEFT 20
#define G_SWITCH_RIGHT 10
#define G_SWITCH_BUTTON 22

void setup() {
 
  // put your setup code here, to run once:
  NRF_CLOCK->LFCLKSRC            = (CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos);
  NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
  NRF_CLOCK->TASKS_LFCLKSTART    = 1;
  delay (1000);

// reprogram the NFC PINS for GPIO

if ((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)){
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NRF_UICR->NFCPINS &= ~UICR_NFCPINS_PROTECT_Msk;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NVIC_SystemReset();
}

delay(1000);
  pinMode(G_SWITCH_UP,      INPUT_PULLUP);
  pinMode(G_SWITCH_DOWN,    INPUT_PULLUP);
  pinMode(G_SWITCH_LEFT,    INPUT_PULLUP);
  pinMode(G_SWITCH_RIGHT,   INPUT_PULLUP);
  pinMode(G_SWITCH_BUTTON,  INPUT_PULLUP );
  pinMode(LED_BUILTIN,      OUTPUT);
  
  Serial.begin(250000);

  delay(1000);

}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)

  Serial.print(!digitalRead(G_SWITCH_UP));     Serial.print(" ");
  Serial.print(!digitalRead(G_SWITCH_DOWN));   Serial.print(" ");
  Serial.print(!digitalRead(G_SWITCH_LEFT));   Serial.print(" ");
  Serial.print(!digitalRead(G_SWITCH_RIGHT));  Serial.print(" ");
  Serial.print(!digitalRead(G_SWITCH_BUTTON)); Serial.println();
  
  delay(100);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(100);                       // wait for a second

}

this is the output:

0 0 1 0 0

0 0 1 0 0

0 0 1 0 0

0 0 1 0 0

0 0 1 0 0

0 0 1 0 0

0 0 1 0 0

Thank you for any guidance.

Greg

Related