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

Struggling with basic GPIO read on NRF52

Hello, I am trying to develop on the NRF52. I have the development board and have been spending time with the SDK and documentation. I understand how the GPIO should work, but I can't seem to get it to do a basic read.

I have a five position switch attached to pins 8, 9, and 10. Trying to detect when the pins are high.

I'm using the LED's on the Dev board as debugging tools.


//5 Position Switch Pins
#define SWITCH_0 8
#define SWITCH_1 9
#define SWITCH_2 10

//5 position switch value
uint32_t fiveposition = 0;

static void gpio_init(void)
{
		//initialize the 5 Position Switch GPIO
		nrf_gpio_cfg_sense_input(SWITCH_0, NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH);
		nrf_gpio_cfg_sense_input(SWITCH_1, NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH);
		nrf_gpio_cfg_sense_input(SWITCH_2, NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH);

		//turn on GPIO Nested Vector Inturrupt
		//NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Msk;
    //NVIC_EnableIRQ(GPIOTE_IRQn);
	
		//Setup LED's for debugging 5 position switch
		nrf_gpio_cfg_output(BSP_LED_0);
		nrf_gpio_cfg_output(BSP_LED_1);
		nrf_gpio_cfg_output(BSP_LED_2);
		nrf_gpio_cfg_output(BSP_LED_3);
		nrf_gpio_pin_clear(BSP_LED_0);
		nrf_gpio_pin_clear(BSP_LED_1);
		nrf_gpio_pin_clear(BSP_LED_2);
		nrf_gpio_pin_clear(BSP_LED_3);

}

int main(void)
{
		gpio_init();
	
    while (true)
    {
				uint32_t switch0 = 0;
				uint32_t switch1 = 0;
				uint32_t switch2 = 0;
				switch0 = nrf_gpio_pin_read(SWITCH_0);
				switch1 = nrf_gpio_pin_read(SWITCH_1);
				switch2 = nrf_gpio_pin_read(SWITCH_2);
			
				if (switch0 == 1) {
					nrf_gpio_pin_set(BSP_LED_0);
				}
				else {
					nrf_gpio_pin_clear(BSP_LED_0);
				}
				
				if (switch1 == 1) {
					nrf_gpio_pin_set(BSP_LED_1);
				}
				else {
					nrf_gpio_pin_clear(BSP_LED_1);
				}
				
				if (switch2 == 1) {
					nrf_gpio_pin_set(BSP_LED_2);
				}
				else {
					nrf_gpio_pin_clear(BSP_LED_2);
				}			
    }
		
}
Parents
  • Why do you say the switch numbers should be 13, 14 and 15 when he states that he has a 5-position switch attached to pins 8, 9 and 10? He doesn't say he's trying to detect the buttons on the board, he's trying to detect his own switch. And you can't really say whether it should be a pull-up or a pull-down since he doesn't state whether the common terminal on the 5-position switch is V+ or GND. If it's GND then he should change it to a pullup, if it's V+ however, then the pulldown is correct.

Reply
  • Why do you say the switch numbers should be 13, 14 and 15 when he states that he has a 5-position switch attached to pins 8, 9 and 10? He doesn't say he's trying to detect the buttons on the board, he's trying to detect his own switch. And you can't really say whether it should be a pull-up or a pull-down since he doesn't state whether the common terminal on the 5-position switch is V+ or GND. If it's GND then he should change it to a pullup, if it's V+ however, then the pulldown is correct.

Children
No Data
Related