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

Gpio configuration and usage

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)
    {

    }
}

Parents
  • Hi Johnny

    P0.18 should not be used as a GPIO as it is the RESET button and the only pin that can be used like that. I suggest using P0.15, P0.16, and P0.17 instead, these pins have no other functions than being GPIO pins. Please refer to the product specification when assigning GPIO pins. This post should be helpful to let you toggle your pins, please look at that. My colleague Martin also links to a very helpful tutorial on the matter of using the various nRF52 peripherals.

    Best regards,

    Simon

Reply
  • Hi Johnny

    P0.18 should not be used as a GPIO as it is the RESET button and the only pin that can be used like that. I suggest using P0.15, P0.16, and P0.17 instead, these pins have no other functions than being GPIO pins. Please refer to the product specification when assigning GPIO pins. This post should be helpful to let you toggle your pins, please look at that. My colleague Martin also links to a very helpful tutorial on the matter of using the various nRF52 peripherals.

    Best regards,

    Simon

Children
No Data
Related