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

Uncontrollable pins in nRF52840 GPIO Port 1

I've been trying to toggle GPIO P1.01 and P1.02 to no avail; P1.01 is always off, and P1.02 is always on from the moment the board is powered, regardless of calls to GPIO functions. These pins don't behave as expected even when I manually set the appropriate bits of P1OUT in the Segger IDE debugger. Pins P1.00, P1.03, P1.04, and P1.05 all behave as expected. I'm working with the nRF52840-DK, but I've had the same issues with a custom board. I looked in the datasheet for the nRF52840 to see if these pins have any other function I'm not taking into account, but I couldn't find anything along those lines. Any advice would be greatly appreciated! Here's my code:

/*
 * Copyright (c) 2019 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/types.h>
#include <stddef.h>
#include <errno.h>

#include <zephyr.h>
#include <sys/printk.h>
#include <device.h>
#include <devicetree.h>
#include <drivers/gpio.h>


//GPIO for Relay Ctl: port 1 pins 0-5
#define rly1CtlPin0  0
#define rly1CtlPin1  1

#define rly2CtlPin0  2
#define rly2CtlPin1  3

#define rly3CtlPin0  4
#define rly3CtlPin1  5


//100ms delay
#define SLEEP_MS   100

//struct device *gpio0dev;
struct device *gpio1dev;

void main(void)
{
  gpio1dev = device_get_binding("GPIO_1");
  if(gpio1dev == NULL)
    printk("Uh oh! Something's wrong with the gpio devices!\n");

  gpio_pin_configure(gpio1dev, rly1CtlPin0, GPIO_OUTPUT_LOW);
  gpio_pin_configure(gpio1dev, rly1CtlPin1, GPIO_OUTPUT_LOW);
  gpio_pin_configure(gpio1dev, rly2CtlPin0, GPIO_OUTPUT_LOW);
  gpio_pin_configure(gpio1dev, rly2CtlPin1, GPIO_OUTPUT_LOW);
  gpio_pin_configure(gpio1dev, rly3CtlPin0, GPIO_OUTPUT_LOW);
  gpio_pin_configure(gpio1dev, rly3CtlPin1, GPIO_OUTPUT_LOW);

  while(1){
    gpio_pin_set(gpio1dev, rly1CtlPin0, 1);
    printk("rly1CtlPin0 is ON\n");
    k_msleep(10*SLEEP_MS);

    gpio_pin_set(gpio1dev, rly1CtlPin0, 0);
    printk("rly1CtlPin0 is OFF\n");
    k_msleep(10*SLEEP_MS);

    gpio_pin_set(gpio1dev, rly1CtlPin1, 1);
    printk("rly1CtlPin1 is ON\n");
    k_msleep(10*SLEEP_MS);

    gpio_pin_set(gpio1dev, rly1CtlPin1, 0);
    printk("rly1CtlPin1 is OFF\n");
    k_msleep(10*SLEEP_MS);

    gpio_pin_set(gpio1dev, rly2CtlPin0, 1);
    printk("rly2CtlPin0 is ON\n");
    k_msleep(10*SLEEP_MS);

    gpio_pin_set(gpio1dev, rly2CtlPin0, 0);
    printk("rly2CtlPin0 is OFF\n");
    k_msleep(10*SLEEP_MS);

    gpio_pin_set(gpio1dev, rly2CtlPin1, 1);
    printk("rly2CtlPin1 is ON\n");
    k_msleep(10*SLEEP_MS);

    gpio_pin_set(gpio1dev, rly2CtlPin1, 0);
    printk("rly2CtlPin1 is OFF\n");
    k_msleep(10*SLEEP_MS);

    gpio_pin_set(gpio1dev, rly3CtlPin0, 1);
    printk("rly3CtlPin0 is ON\n");
    k_msleep(10*SLEEP_MS);

    gpio_pin_set(gpio1dev, rly3CtlPin0, 0);
    printk("rly3CtlPin0 is OFF\n");
    k_msleep(10*SLEEP_MS);

    gpio_pin_set(gpio1dev, rly3CtlPin1, 1);
    printk("rly3CtlPin1 is ON\n");
    k_msleep(10*SLEEP_MS);

    gpio_pin_set(gpio1dev, rly3CtlPin1, 0);
    printk("rly3CtlPin1 is OFF\n");
    k_msleep(10*SLEEP_MS);
  }//do nothing else

}

Related