Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Help with Blinky example

I cannot get the blinky example to work with my NRF52 development kit.  I used the example in the pca10040/blank/ses folder and it worked fine.  I then modified the code per the attached.  I have an LED connected on pin 14 and there is a kit LED connected on pin 17.  With the code attached the LED on pin 14 lights but pin 17 does nothing.  There is no flashing of the LEDs.  Thanks for the help.  I know this is a stupidly simple question.  It compiles and flashes fine.  I get to no errors or warnings.  As I said, I can get the example code to work where the 4 LEDs are toggled every 500 ms.  I wanted to learn by doing something different.

#include <stdbool.h>
#include <stdint.h>
#include "nrf_delay.h"
#include "nrf_gpio.h"

 #define LED 14
 #define LED1 17

int main(void)
{
nrf_gpio_cfg_output(LED);
nrf_gpio_cfg_output(LED1);

  while(1)
  {

  nrf_gpio_pin_set(LED);
  nrf_gpio_pin_set(LED1);
  nrf_delay_ms(500);
  nrf_gpio_pin_clear(LED);
nrf_gpio_pin_clear(LED1);
}
}

  • Hello,

    Do you have an externally connected LED to P0.14? This pin is assigned to button 2 on the nRF52 DK, so it can't control any of the board LEDs (for pin assignments you can look at the silkscreen on the boards backside).

    Either way, the problem with the code you posted is that nrf_gpio_pin_set() gets called immediately after nrf_gpio_pin_clear() with no delay in-between.

    Please try to add this delay after turning on the LED:

    while(1)
    {
        nrf_gpio_pin_set(LED);
        nrf_gpio_pin_set(LED1);
         nrf_delay_ms(500); // Stay ON for 500 ms (LEDs are active low)
        nrf_gpio_pin_clear(LED);
        nrf_gpio_pin_clear(LED1);
        nrf_delay_ms(500); // Stay OFF for 500 ms
    }

    Hope this helps!

    Best regards,

    Vidar

Related