nRF Connect SDK Fundamentals Lesson 6 exercise 1: Error with i2c_write_read_dt

I am using the nRF52840DK with nRFConnect for VS Code. In Lesson 6 Exercise 1, I connected the DK to a BME280 board I purchased online. The board exposes the four pins needed for I2C comms and I connected them to the DK pins as directed in the exercise. I also use this BME board with a nRF52840 Feather board from Adafruit - and I know it's address is 0x76. I altered the device overlay as shown below to account for this address change. 

&i2c21 {
status = "okay";
pinctrl-0 = <&i2c21_default>;
pinctrl-1 = <&i2c21_sleep>;
pinctrl-names = "default", "sleep";
mysensor: mysensor@76{
compatible = "i2c-device";
status = "okay";
reg = < 0x76 >;
};
};

&pinctrl {
/omit-if-no-ref/ i2c21_default: i2c21_default {
group1 {
psels = <NRF_PSEL(TWIM_SCL, 1, 11)>,
<NRF_PSEL(TWIM_SDA, 1, 12)>;
};
};
/omit-if-no-ref/ i2c21_sleep: i2c21_sleep {
group1 {
psels = <NRF_PSEL(TWIM_SCL, 1, 11)>,
<NRF_PSEL(TWIM_SDA, 1, 12)>;
};
};
};

The software builds and flashes, but the output I get when I run the program is : Failed to read register d0, which means the first call to i2c_write_read_dt failed.

When I probed deeper, I found that the error returned was -5 - which I believe is a general read/write failure. When I connected my logic analyzer (screenshots below) I found that the DK wrote 0x76 ACK and 0xD0 ACK as expected, but the BME never replied. When I probed the Feather board I noticed that the sequence written by the Feather was 0x76 ACK, 0x76 ACK, 0xD0, and the same BME board replied with the expected 0x60. Has anyone seen this, or do you have any hints to fix it?

Thanks Lonnie

Parents Reply Children
  • I am having trouble attaching the log in the <code> section of insert - so the log is  attached below. The "Problems" Tab is included at the end of the log file. I am using nRF Connect SDK 3.2.1.

    The problem is only on the DK. The feather, which is programed from the Arduino IDE using Adafruit bluefruit and BME280 libraries, works fine.

    * Executing task: nRF Connect: Build [pristine]: l6_e1/build

    Building l6_e1
    west build --build-dir c:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build c:/myfw/ncs-fund/ncs-fund/l6/l6_e1 --pristine --board nrf52840dk/nrf52840 -- -DCONF_FILE="prj.conf" -DDTC_OVERLAY_FILE=boards/nrf52840dk_nrf52840.overlay -DDEBUG_THREAD_INFO=On -DCONFIG_DEBUG_THREAD_INFO=y -Dl6_e1_DEBUG_THREAD_INFO=On

    -- west build: generating a build system
    Loading Zephyr module(s) (Zephyr base): sysbuild_default
    -- Found Python3: C:/ncs/toolchains/66cdf9b75e/opt/bin/python.exe (found suitable version "3.12.4", minimum required is "3.10") found components: Interpreter
    -- Cache files will be written to: C:/ncs/v3.2.1/zephyr/.cache
    -- Found west (found suitable version "1.4.0", minimum required is "0.14.0")
    -- Board: nrf52840dk, qualifiers: nrf52840
    Parsing C:/ncs/v3.2.1/zephyr/share/sysbuild/Kconfig
    Loaded configuration 'C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build/_sysbuild/empty.conf'
    Merged configuration 'C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build/_sysbuild/empty.conf'
    Configuration saved to 'C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build/zephyr/.config'
    Kconfig header saved to 'C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build/_sysbuild/autoconf.h'
    --
    ***************************
    * Running CMake for l6_e1 *
    ***************************

    Loading Zephyr default modules (Zephyr base).
    -- Application: C:/myfw/ncs-fund/ncs-fund/l6/l6_e1
    -- CMake version: 3.21.0
    -- Found Python3: C:/ncs/toolchains/66cdf9b75e/opt/bin/python.exe (found suitable version "3.12.4", minimum required is "3.10") found components: Interpreter
    -- Cache files will be written to: C:/ncs/v3.2.1/zephyr/.cache
    -- Zephyr version: 4.2.99 (C:/ncs/v3.2.1/zephyr)
    -- Found west (found suitable version "1.4.0", minimum required is "0.14.0")
    -- Board: nrf52840dk, qualifiers: nrf52840
    -- Found host-tools: zephyr 0.17.0 (C:/ncs/toolchains/66cdf9b75e/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.17.0 (C:/ncs/toolchains/66cdf9b75e/opt/zephyr-sdk)
    -- Found Dtc: C:/ncs/toolchains/66cdf9b75e/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
    -- Found BOARD.dts: C:/ncs/v3.2.1/zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840.dts
    -- Found devicetree overlay: boards/nrf52840dk_nrf52840.overlay
    -- Generated zephyr.dts: C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build/l6_e1/zephyr/zephyr.dts
    -- Generated pickled edt: C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build/l6_e1/zephyr/edt.pickle
    -- Generated devicetree_generated.h: C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build/l6_e1/zephyr/include/generated/zephyr/devicetree_generated.h
    Parsing C:/ncs/v3.2.1/zephyr/Kconfig
    Loaded configuration 'C:/ncs/v3.2.1/zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840_defconfig'
    Merged configuration 'C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/prj.conf'
    Merged configuration 'C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build/l6_e1/zephyr/misc/generated/extra_kconfig_options.conf'
    Merged configuration 'C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build/l6_e1/zephyr/.config.sysbuild'
    Configuration saved to 'C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build/l6_e1/zephyr/.config'
    Kconfig header saved to 'C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build/l6_e1/zephyr/include/generated/zephyr/autoconf.h'
    -- Found GnuLd: c:/ncs/toolchains/66cdf9b75e/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38")
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: C:/ncs/toolchains/66cdf9b75e/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
    -- Found gen_kobject_list: C:/ncs/v3.2.1/zephyr/scripts/build/gen_kobject_list.py
    -- Configuring done
    -- Generating done
    -- Build files have been written to: C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build/l6_e1
    -- Configuring done
    -- Generating done
    -- Build files have been written to: C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build
    ←[92m-- west build: building application
    [5/10] Performing build step for 'l6_e1'
    [4/168] Generating include/generated/zephyr/version.h
    -- Zephyr version: 4.2.99 (C:/ncs/v3.2.1/zephyr), build: ncs-v3.2.1
    [5/168] Generating include/generated/zephyr/syscall_dispatch.c, include/generated/zephyr/s[6/168] Generating include/generated/device-api-sections.ld, include/generated/device-api-[7/168] Generating include/generated/zephyr/syscall_dispatch.c, include/generated/zephyr/s[9/168] Building C object zephyr/CMakeFiles/offsets.dir/arch/arm/core/offsets/offsets.c.ob[10/168] Building C object zephyr/CMakeFiles/offsets.dir/arch/arm/core/offsets/offsets.c.o[11/168] Building C object zephyr/CMakeFiles/zephyr.dir/C_/ncs/v3.2.1/nrf/lib/boot_banner/[11/168] Building C object zephyr/CMakeFiles/zephyr.dir/C_/ncs/v3.2.1/nrf/subsys/partition[13/168] Building C object zephyr/CMakeFiles/zephyr.dir/C_/ncs/v3.2.1/nrfxlib/crypto/nrf_c[15/168] Building C object zephyr/soc/soc/nrf52840/CMakeFiles/soc__nordic.dir/validate_bin[18/168] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__[19/168] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__[20/168] Building ASM object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core[21/168] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__[22/168] Building C object zephyr/arch/common/CMakeFiles/arch__common.dir/sw_isr_common.c.[26/168] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/fatal.[27/168] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/tls.c.[29/168] Building ASM object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/nmi_[30/168] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__[31/168] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__[32/168] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__[34/168] Building ASM object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core[36/168] Building ASM object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core[37/168] Building ASM object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core[38/168] Building C object zephyr/soc/soc/nrf52840/CMakeFiles/soc__nordic.dir/validate_bas[41/168] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__[43/168] Building ASM object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core[44/168] Building C object zephyr/arch/arch/arm/core/mpu/CMakeFiles/arch__arm__core__mpu.d[46/168] Building C object zephyr/arch/arch/arm/core/mpu/CMakeFiles/arch__arm__core__mpu.d[47/168] Building C object zephyr/lib/libc/picolibc/CMakeFiles/lib__libc__picolibc.dir/ass[48/168] Building C object zephyr/lib/libc/picolibc/CMakeFiles/lib__libc__picolibc.dir/cbp[49/168] Building C object zephyr/lib/libc/picolibc/CMakeFiles/lib__libc__picolibc.dir/err[52/168] Building C object zephyr/lib/libc/picolibc/CMakeFiles/lib__libc__picolibc.dir/loc[53/168] Building C object zephyr/lib/libc/picolibc/CMakeFiles/lib__libc__picolibc.dir/std[56/168] Building C object zephyr/lib/libc/common/CMakeFiles/lib__libc__common.dir/source/[57/168] Building C object zephyr/lib/libc/common/CMakeFiles/lib__libc__common.dir/source/[59/168] Building C object zephyr/soc/soc/nrf52840/CMakeFiles/soc__nordic.dir/validate_ena[60/168] Building C object zephyr/soc/soc/nrf52840/CMakeFiles/soc__nordic.dir/common/reboo[61/168] Building C object zephyr/soc/soc/nrf52840/CMakeFiles/soc__nordic.dir/common/gpiot[62/168] Building C object zephyr/soc/soc/nrf52840/CMakeFiles/soc__nordic.dir/nrf52/soc.c.[63/168] Building C object zephyr/soc/soc/nrf52840/CMakeFiles/soc__nordic.dir/common/gppi_[65/168] Building C object zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_[67/168] Building C object zephyr/drivers/console/CMakeFiles/drivers__console.dir/uart_con[69/168] Linking C static library zephyr\arch\arch\arm\core\cortex_m\libarch__arm__core__c[71/168] Building C object zephyr/drivers/i2c/CMakeFiles/drivers__i2c.dir/i2c_nrfx_twi_com[73/168] Building C object zephyr/drivers/i2c/CMakeFiles/drivers__i2c.dir/i2c_nrfx_twi.c.o[74/168] Building C object zephyr/drivers/pinctrl/CMakeFiles/drivers__pinctrl.dir/common.c[76/168] Building C object zephyr/drivers/timer/CMakeFiles/drivers__timer.dir/nrf_rtc_time[78/168] Building C object modules/nrf/drivers/hw_cc3xx/CMakeFiles/..__nrf__drivers__hw_cc[79/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__[81/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__hal_nordic__nrfx.dir/C_/ncs/v3.2.1/modules/hal/nordic/nrfx/bsp/stable/mdk/system_nrf52840.[82/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__[85/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__[87/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__hal_nordic__nrfx.dir/C_/ncs/v3.2.1/modules/hal/nordic/nrfx/helpers/nrfx_flag32_allocator.c[88/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__hal_nordic__nrfx.dir/C_/ncs/v3.2.1/modules/hal/nordic/nrfx/drivers/src/nrfx_clock_hfclk192[91/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__hal_nordic__nrfx.dir/C_/ncs/v3.2.1/modules/hal/nordic/nrfx/drivers/src/nrfx_clock_hfclkaud[92/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__[93/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__hal_nordic__nrfx.dir/C_/ncs/v3.2.1/modules/hal/nordic/nrfx/drivers/src/nrfx_clock_xo24m.c.[94/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__hal_nordic__nrfx.dir/C_/ncs/v3.2.1/modules/hal/nordic/nrfx/drivers/src/nrfx_clock_lfclk.c.[96/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__[97/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__[99/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__[100/168] Linking C static library modules\nrf\drivers\hw_cc3xx\lib..__nrf__drivers__hw_cc[136/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules__hal_nordic__nrfx.dir/C_/ncs/v3.2.1/modules/hal/nordic/nrfx/drivers/src/nrfx_twi_twim.c.ob[139/168] Building C object modules/hal_nordic/modules/hal_nordic/nrfx/CMakeFiles/modules_[157/168] Linking C static library modules\hal_nordic\modules\hal_nordic\nrfx\libmodules__[159/168] Linking C static library modules\hal_nordic\modules\hal_nordic\nrfx\libmodules__[168/168] Linking C executable zephyr\zephyr.elf
    Memory region Used Size Region Size %age Used
    FLASH: 36188 B 1 MB 3.45%
    RAM: 6784 B 256 KB 2.59%
    IDT_LIST: 0 GB 32 KB 0.00%
    Generating files from C:/myfw/ncs-fund/ncs-fund/l6/l6_e1/build/l6_e1/zephyr/zephyr.elf for board: nrf52840dk
    [8/10] cmd.exe /C "cd /D C:\myfw\ncs-fund\ncs-fund\l6\l6_e1\build\_sysbuild && C:\ncs\tool[10/10] Generating ../merged.hex
    * Terminal will be reused by tasks, press any key to close it.


    Here is the Problems Tab:
    The I2C drivers must be enabled by CONFIG_I2C to be included in the build

    [{
    "resource": "/c:/myfw/ncs-fund/ncs-fund/l6/l6_e1/prj.conf",
    "owner": "Kconfig no context",
    "severity": 2,
    "message": "The active build context 'build' does not use this file.",
    "startLineNumber": 1,
    "startColumn": 1,
    "endLineNumber": 1,
    "endColumn": 1,
    "modelVersionId": 1,
    "origin": "extHost1"
    }]

Related