Building ccs811 sensor Sample code on a nrf9160dk

I am trying to build the ccs811 sample code provided by zephyr. This is very new to me and I'm struggling to get it to work. I am currently using SDK version 2.3.0, toolchain 2.3.0, but building using nrF Connect in VS Code. When i make the build configuration and select the nrf9160dk_nrf9160 as my target board this is the terminal error output: 

In file included from C:\ncs\v2.3.0\zephyr\include\zephyr\sys\util_macro.h:34,
                 from C:\ncs\v2.3.0\zephyr\include\zephyr\sys\atomic.h:16,
                 from C:\ncs\v2.3.0\zephyr\include\zephyr\kernel_includes.h:21,
                 from C:\ncs\v2.3.0\zephyr\include\zephyr\kernel.h:17,
                 from c:\ncs\v2.3.0\zephyr\samples\sensor\ccs811\src\main.c:8:
../src/main.c: In function 'main':
C:\ncs\v2.3.0\zephyr\include\zephyr\sys\util.h:78:55: error: size of unnamed array is negative
   78 | #define ZERO_OR_COMPILE_ERROR(cond) ((int) sizeof(char[1 - 2 * !(cond)]) - 1)
      |                                                       ^
C:\ncs\v2.3.0\zephyr\include\zephyr\sys\util_internal.h:72:26: note: in definition of macro '__DEBRACKET'
   72 | #define __DEBRACKET(...) __VA_ARGS__
      |                          ^~~~~~~~~~~
C:\ncs\v2.3.0\zephyr\include\zephyr\sys\util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
   64 |         __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
      |         ^~~~~~~~~~~~~~~~~~~~
C:\ncs\v2.3.0\zephyr\include\zephyr\sys\util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
   59 |         __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
      |         ^~~~~~~~~~~
C:\ncs\v2.3.0\zephyr\include\zephyr\sys\util_macro.h:157:9: note: in expansion of macro 'Z_COND_CODE_1'
  157 |         Z_COND_CODE_1(_flag, _if_1_code, _else_code)
      |         ^~~~~~~~~~~~~
C:\ncs\v2.3.0\zephyr\include\zephyr\device.h:277:9: note: in expansion of macro 'COND_CODE_1'
  277 |         COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat),                         \
      |         ^~~~~~~~~~~
C:\ncs\v2.3.0\zephyr\include\zephyr\device.h:279:22: note: in expansion of macro 'ZERO_OR_COMPILE_ERROR'
  279 |                     (ZERO_OR_COMPILE_ERROR(0)))
      |                      ^~~~~~~~~~~~~~~~~~~~~
c:\ncs\v2.3.0\zephyr\samples\sensor\ccs811\src\main.c:116:42: note: in expansion of macro 'DEVICE_DT_GET_ONE'
  116 |         const struct device *const dev = DEVICE_DT_GET_ONE(ams_ccs811);
 

It seems to be originating from DEVICE_DT_GET_ONE? However, when I try to build using the suggested target board efr32mg_sltb0004a it builds with no issues, but the other suggested board thingy52_nrf52832 also has the same build error as above. 

Any suggestions on how to fix this please? 

Parents
  • Hi again, finally got back around to working on this. 

    I did the DevAcademy course and gained a lot of understanding of the device tree and overlay files etc. 

    I created this overlay file for the nrf9160dk_nrf9160_ns: 

    arduino_i2c: &i2c2 {
    	compatible = "nordic,nrf-twim";
    	status = "okay";
    	pinctrl-0 = <&i2c2_default>;
    	pinctrl-1 = <&i2c2_sleep>;
    	pinctrl-names = "default", "sleep";
    
        /* Sparkfun Environment Combo uses second I2C address */
    	ccs811: ccs811@5b {
    		compatible = "ams,ccs811";
    		reg = <0x5b>;
    		irq-gpios = <&gpio0 23 GPIO_ACTIVE_LOW>;
    		wake-gpios = <&gpio0 24 GPIO_ACTIVE_LOW>;
    		reset-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
    	};
    };

    to add the ccs811 sensor to the board config. I've put the reset, int, and wake pins on 23, 24, and 25 as they didn't conflict with anything. The application builds successfully. However, when I flash to the 9160 dk DEVICE_DT_GET_ONE(ams_ccs811) returns a NULL pointer. As a result, device_is_ready(dev) says device is not ready and the application doesn't advance. From reading it seems this is because the device isn't initialized. How can I get it to do this?

    Thanks 

  • kew_flex said:
    I've put the reset, int, and wake pins on 23, 24, and 25 as they didn't conflict with anything.

    Looking at the GPIO interfaces of the nRF9160DK it does look like these are used/conflicting, You could test with P0.00, P0.01, P0.14, and P0.15, or use pins that are not listed in GPIO interfacce

Reply Children
No Data
Related