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
  • 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?

Children
No Data
Related