Hello,
I am using the chip nrf52840. I am trying to configure three pins (P0.09, P0.10 and P0.11) as output pins and I am trying to make set and reset functions for them. I used the gpio_toggle example to help me do it. However, I am not doing something right even though I pretty much just copied the example code into my own project and made a few adjustments. Can some please help find me the problem? No matter what I do, the voltage of the pins on P0.10 and P0.11 is low and on P0.09 is high. The short and simple code is listed below. Best regards.
#include "nrf_drv_spi.h" #include "app_util_platform.h" #include "nrf_gpio.h" #include "nrf_delay.h" #include "boards.h" #include "app_error.h" #include <string.h> #include "nrf_log.h" #include "nrf_log_ctrl.h" #include "nrf_log_default_backends.h" #define CS_FLASH_MEMORY_PIN (9UL) #define HOLD_PIN (10UL) #define WRITE_PROTECT_PIN (11UL) void configure_pin_direction_as_output(unsigned long pin){ NRF_GPIO->PIN_CNF[pin] = (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos) | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); } void set_pin(unsigned long pin){ NRF_GPIO->OUTSET = (1UL << pin); } void reset_pin(unsigned long pin){ NRF_GPIO->OUTCLR = (1UL << pin); } void configure_chip_select_pin_of_the_flash_memory(void){ configure_pin_direction_as_output(CS_FLASH_MEMORY_PIN); } void configure_hold_pin_of_the_flash_memory(void){ configure_pin_direction_as_output(HOLD_PIN); } void configure_write_protect_pin_of_the_flash_memory(void){ configure_pin_direction_as_output(WRITE_PROTECT_PIN); } void deactivate_chip_select_pin_of_the_flash_memory(void){ set_pin(CS_FLASH_MEMORY_PIN); } void activate_chip_select_pin_of_the_flash_memory(void){ reset_pin(CS_FLASH_MEMORY_PIN); } void deactivate_hold_pin(void){ set_pin(HOLD_PIN); } void activate_hold_pin(void){ reset_pin(HOLD_PIN); } void deactivate_write_protect_pin(void){ set_pin(WRITE_PROTECT_PIN); } void activate_write_protect_pin(void){ reset_pin(WRITE_PROTECT_PIN); } int main(void) { deactivate_chip_select_pin_of_the_flash_memory(); deactivate_hold_pin(); deactivate_write_protect_pin(); while (1) { } }