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

Cannot get gpio_pin_read to work.

  Hello,

Using an Arduino nano 33 ble which contains a nrf52840.

Using arm-none-eabi-gcc version 9.2.1 in debian/linux, uploading using openocd en gdb.

I tested my problem on 2 different boards and 2 different gpio ports. I started with the blinky example and added reading a button.

The button is a switch to ground and when using pullup for the gpio it should work. But it doesn't, always the else-branch is taken!

What am I doing wrong here?  Thanks in advance, Sietse

/  Test button press on Arduino nano 33 ble

#include <stdbool.h>
#include <stdint.h>
#include "nrf_delay.h"
#include "nrf_gpio.h"

#define LED_DL1         NRF_GPIO_PIN_MAP(1,9)  // Led pwe
#define LED_DL2         NRF_GPIO_PIN_MAP(0,13) // Led builtin
#define ARDUINO_3_PIN   NRF_GPIO_PIN_MAP(1,11) // Digital pin 2
#define BUTTON_2        ARDUINO_3_PIN

int main(void)
{
  nrf_gpio_cfg_input(BUTTON_2, NRF_GPIO_PIN_PULLUP);
  nrf_gpio_cfg_output(LED_DL1);
  nrf_gpio_cfg_output(LED_DL2);
    
  while (true)
    {
      if (nrf_gpio_pin_read(BUTTON_2)) {
	nrf_gpio_pin_toggle(LED_DL2);
	nrf_delay_ms(100);
      }
      else {
	nrf_gpio_pin_toggle(LED_DL2);
	nrf_delay_ms(500);
      }
    }
}

Parents Reply Children
  • Hello,

    I am using a programmer from Olimex and program via de gdb "flash write_image erase <filename>" command. The verify command checks out. Have had no problems so far. Switched several time to the arduino bootloader and back. So i find it difficult to see anything wrong there.

    Note that the programmer only interfaces with the swd, and the only I/O is the button. So there is only interaction with the nrf52840 chip, so I find it hard to believe that it has anything to do with anything arduino.

    The voltages I measure is during the running of the program, so the voltage should be high as long as the button is not pressed because of the internal pullup.

    Finally there is another strange thing. If I use the other led mentioned in the program, LED_DL1, then that does not work, it does not light up.

    Do I understand it correctly that the program above is correct? That the gpio pin should read different values when the button is used?

  • I think I found it!

    The pins that were not working were all from port 1. When I used a pin from port 0 it just works!

    I saw somewhere a define that determines the number of ports for the architecture, and it should be 2. But maybe this is wrong here?

    My custom_board.h is derived from the one from blinky/pca10040, with correct led/button values for the arduino filled in. Also the Makefile is from blinky/pca10040.

    So how do I get access to the second gpio port?

    Thanks for the help,

        Sietse

  • Hello Jared,

    I noticed that the usbd_cdc_acm example completely works, including all the leds and buttons, also those on gpio port #1.

    And with the original blinky example everything works, but NOT the first led (on gpio port #1)!

    Both examples use bsp-functionality. Strange.

  • Hi,

    Great!

    PCA10040(nRF52832) does only have one port, PCA10056 however which is the  Development for nRF52840 has two ports. Try using the PCA10056 instead, it should map the pins correctly then.

    regards

    Jared 

Related