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

nRF5340-DK & CCS811 sensor, doesn't reach main()

Hi,

I'm working with the CCS811 sensor example from the `v1.5.1/zephyr/samples/sensor` folder and I managed to compile it successfully after modifying the files in the `ccs811/boards` directory. When I debug the solution, the debugger enters in continued execution mode and never reaches the main() function. Every time I hit  "Pause", the code always pauses in the same place, as it is shown in the following screen capture:

I'm using the nRF Connect SDK V1.5.1 (tried with V1.5.0 also). In the `ccs811/boards` folder I have two files:

nrf5340dk_nrf5340_cpuapp.overlay:

&i2c1 {
        status = "okay";
        sda-pin = <0>;
        scl-pin = <1>;

	/* Sparkfun Environment Combo uses second I2C address */
        ccs811: ccs811@5b {
                compatible = "ams,ccs811";
                reg = <0x5b>;
                label = "CCS811";
                irq-gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
                wake-gpios = <&gpio0 5 GPIO_ACTIVE_LOW>;
                reset-gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
        };
};

And nrf5340dk_nrf5340_cpuapp.conf:

CONFIG_STDOUT_CONSOLE=y
CONFIG_SENSOR=y
CONFIG_CCS811=y
#CONFIG_CCS811_DRIVE_MODE_2=y
#CONFIG_CCS811_TRIGGER_GLOBAL_THREAD=y
#CONFIG_CCS811_TRIGGER_OWN_THREAD=y

Any hints about what could be the issue? Thanks in advance!

Parents Reply Children
  • Hi Simon, thanks for your help!

    Evidently, the execution hangs inside cs811_init(), concretely in the k_msleep() function:

    #if DT_INST_NODE_HAS_PROP(0, wake_gpios)
    	drv_data->wake_gpio = device_get_binding(DT_INST_GPIO_LABEL(0, wake_gpios));
    	if (drv_data->wake_gpio == NULL) {
    		LOG_ERR("Failed to get pointer to WAKE device: %s",
    			DT_INST_GPIO_LABEL(0, wake_gpios));
    		return -EINVAL;
    	}
    
    	/*
    	 * Wakeup pin should be pulled low before initiating
    	 * any I2C transfer.  If it has been tied to GND by
    	 * default, skip this part.
    	 */
    	gpio_pin_configure(drv_data->wake_gpio, WAKE_PIN,
    			   GPIO_OUTPUT_INACTIVE
    			   | DT_INST_GPIO_FLAGS(0, wake_gpios));
    
    	set_wake(drv_data, true);
    	k_msleep(1);
    #endif

    If I comment k_msleep(1); the code goes on forward, but it gets stuck again in any subsequent k_msleep() instance. If I comment out every instance of k_msleep(), the code reaches the main() function.

    Could it be an issue with the clock configuration? Any hint about what could be the cause?

    I didn't get any hard fault errors in the serial terminal.

    Thanks in advance!

    EDIT:

    Nevermind, I changed the following pins in my nrf5340dk_nrf5340_cpuapp.overlay:

    sda-pin = <34>; // P1.02 (34)
    scl-pin = <35>; // P1.03 (35)
    
    irq-gpios = <&gpio0 36 GPIO_ACTIVE_LOW>; // P1.04 (36)

    And now it runs fine without hanging in the k_msleep() instances. Perhaps, the sensor wasn't responding because of a conflict with the pins I was trying to use and that was causing the processor to hang in the css811_init() function? Not sure though...

    Thanks!

Related