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);
}
}
}