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

toggle a pin of nrf52

hi,

I am using nrf 52 DK and  softdevice S132,PCA10040 board . I need to toggle a pin,set a pin,reset a pin .can anyone take this ticket  to a sample code/ code snippet and which packs do i need to install.basically i just want to write a simple code where i want to toggle a pin continously .

Parents
  • Hey Kirt, this shouldn't be a problem at all. I do believe this is also a common question on the forum.

    Simply include nrf_gpio.h in your C/C++ source file. This is Nordic's API that will let you interface with board at a high level. You can read more about GPIO here.

    I would define a pin at the top of your code like the following. 

    #include "nrf_delay.h"
    #include "nrf_gpio.h"
    
    #define YOUR_PIN 			NRF_GPIO_PIN_MAP(1,3)	// Example connection - P1.03
    #define FREQUENcY_MS        500
    
    // in your init function use this to configure the pin: 
    nrf_gpio_cfg_output(YOUR_PIN);  /* Initialize with default config of pin */
    
    
    // probably you will put this in main loop ...
    
    nrf_gpio_pin_toggle(YOUR_PIN);
    nrf_delay_ms(FREQUENCY_MS);
    
    // other useful gpio functions 
    // nrf_gpio_pin_set(YOUR_PIN);
    // nrf_gpio_pin_clear(YOUR_PIN);

    The NRF_GPIO_PIN_MAP is a simple macro that converts the Pin # printed on the DK to the appropriate map for the board. The cfg_output simply sets the pin as an output instead of an input (no need for internal pull resistors). 

    Then use the nrf_delay_ms function to create your frequency to continuously toggle a pin.

    Hopefully this helps,

    Rishi

Reply
  • Hey Kirt, this shouldn't be a problem at all. I do believe this is also a common question on the forum.

    Simply include nrf_gpio.h in your C/C++ source file. This is Nordic's API that will let you interface with board at a high level. You can read more about GPIO here.

    I would define a pin at the top of your code like the following. 

    #include "nrf_delay.h"
    #include "nrf_gpio.h"
    
    #define YOUR_PIN 			NRF_GPIO_PIN_MAP(1,3)	// Example connection - P1.03
    #define FREQUENcY_MS        500
    
    // in your init function use this to configure the pin: 
    nrf_gpio_cfg_output(YOUR_PIN);  /* Initialize with default config of pin */
    
    
    // probably you will put this in main loop ...
    
    nrf_gpio_pin_toggle(YOUR_PIN);
    nrf_delay_ms(FREQUENCY_MS);
    
    // other useful gpio functions 
    // nrf_gpio_pin_set(YOUR_PIN);
    // nrf_gpio_pin_clear(YOUR_PIN);

    The NRF_GPIO_PIN_MAP is a simple macro that converts the Pin # printed on the DK to the appropriate map for the board. The cfg_output simply sets the pin as an output instead of an input (no need for internal pull resistors). 

    Then use the nrf_delay_ms function to create your frequency to continuously toggle a pin.

    Hopefully this helps,

    Rishi

Children
No Data
Related