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

Writing to GPIO on nrf5340-DK

I'm working with the latest v1.6.1 nrf SDK, and was able to get the Blinky sample code to work.. But trying to translate that to toggling other GPIO isn't working.  I also tried the code here:  https://devzone.nordicsemi.com/f/nordic-q-a/67810/reading-and-writing-to-gpio-pins-from-a-sample-zephyr-project  but when that code is loaded, nothing happens.

main.c

/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

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

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   1000

/* The devicetree node identifier for the "led0" alias. */
#define LED1_NODE DT_ALIAS(led1)

#if DT_NODE_HAS_STATUS(LED1_NODE, okay)
#define LED1	DT_GPIO_LABEL(LED1_NODE, gpios)
#define PIN	DT_GPIO_PIN(LED1_NODE, gpios)
#define FLAGS	DT_GPIO_FLAGS(LED1_NODE, gpios)
#else
/* A build error here means your board isn't set up to blink an LED. */
#error "Unsupported board: led0 devicetree alias is not defined"
#define LED0	""
#define PIN	0
#define FLAGS	0
#endif

void main(void)
{
	const struct device *dev;
        const struct device *dev0;
	bool led_is_on = true;
	int ret;
        dev0= device_get_binding("GPIO_0");
        gpio_pin_configure(dev0,27,GPIO_OUTPUT);
	dev = device_get_binding(LED1);
	if (dev == NULL) {
		return;
	}

	ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
	if (ret < 0) {
		return;
	}

	while (1) {
                gpio_pin_toggle(dev0,27);
		gpio_pin_set(dev, PIN, (int)led_is_on);
		led_is_on = !led_is_on;
		k_msleep(SLEEP_TIME_MS);
	}
}

In the above code, the LED blinks properly, but P0.27 remains pulled high by the pullup resistors on my board.  I've tried other GPIO as well with the same results.

Parents Reply Children
No Data
Related