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

LED suddenly light up - nRF Connect SDK tutorial

Hi, I am following the tutorial and have some questions during the implementation.

devzone.nordicsemi.com/.../nrf-connect-sdk-tutorial---part-2-ncs-v1-4-0

A red led increasing its intensity but every 2 cycles the blue led suddenly lights up. 

I have erased the whole flash but nothing changed.

And I have connected the serial terminal to see if the board is reset. But "PWM Application has started!" only shows once.

Any suggestions are welcome.

thingy91_nrf9160ns.overlay

&pwm0 {
status = "okay";
ch0-pin = <29>;
};

main.c

#include <zephyr.h>
#include <device.h>
#include <stdio.h>
#include <sys/printk.h>
#include <sys/util.h>
#include <sys_clock.h>
#include <drivers/pwm.h>
#include <kernel.h>


#include <logging/log.h>
LOG_MODULE_REGISTER(modules_common, 4);


#define PWM_DEVICE_NAME DT_PROP(DT_NODELABEL(pwm0), label)
#define PWM_CH0_PIN DT_PROP(DT_NODELABEL(pwm0), ch0_pin)
#define PWM_CH1_PIN DT_PROP(DT_NODELABEL(pwm0), ch1_pin)
#define PWM_CH2_PIN DT_PROP(DT_NODELABEL(pwm0), ch2_pin)

#define PWM_PERIOD 253


static const struct device* pwm_init()
{
	const struct device *pwm_dev = device_get_binding(PWM_DEVICE_NAME);
    if (pwm_dev == NULL) {
        printk("Didn't find LED device %s\n", PWM_DEVICE_NAME);
        return NULL;
    }
    return pwm_dev;
}


void main(void)
{
    printk("PWM Application has started!\r\n");
    
    const struct device *pwm_dev = pwm_init();
    if (pwm_dev == NULL) return;

    uint8_t pulse = 0;

    while (1) {
        pulse = pulse +10;
        if (pulse > PWM_PERIOD) {
            pulse = 0;
        }
        if (pwm_pin_set_usec(pwm_dev, PWM_CH0_PIN, PWM_PERIOD, pulse, 0)) {
            printk(".");
        }
        //if (pwm_pin_set_usec(pwm_dev, PWM_CH1_PIN, PWM_PERIOD, pulse, 0)) {
        //    printk(".");
        //}
        k_sleep(K_MSEC(200));
    }
}

Environment:

- nRF Connect SDK 1.5.1 installed by Toolchain manager

- Thingy:91 and JLink debugger 

Related