nrf52840dk getting I2C error code -5 with bme280 (Lesson 6 DevAcademy) even with the solution code.

I am working my way through the DevAcadmy (nRF Connect SDK Fundamentals) using an nRF52840 development kit.

In lesson 6, exercise 1, I try to get an I2C with a BME280 to work. I can't even read the device ID (error -5).

The I2C bus is ready - device_is_ready(). The sensor works with an ESP32 and with an Arduino Nano. The wiring is triple-checked.

I managed to get information from an I2C scanner on the nRF52840. The I2C address is set to the value from the scanner. The devicetree shows the expected values for SDA and SCL. I built a configuration for the nRF52840 board. No luck.

I even tried with the given solution with the right board. Same behavior.

I2C-address is 0x76. I tried to read the device ID (0xd0) with i2c_write_read and with an i2c_write then with an i2c_read. When trying to i2c_write there is this error -5.

Any hints what I can try next?

I appreciate any help that leads me in the right direction.

Parents
  • Hi there,

    I found a solution to my question. After reading numerous posts, one post got my attention.

    In the lesson 6 exercise 1 and in the solution, the overlay file nrf52840dk_nrf52840.overlay looks like

    &i2c0 {
        status = "okay";
        pinctrl-0 = <&i2c0_default>;
        pinctrl-1 = <&i2c0_sleep>;
        pinctrl-names = "default", “sleep”;
        bme280: bme280@76 {
            compatible = "bosch,bme280";
            status = "okay";
            reg = <0x76>;
        };
    };
    ...

    I changed “mysensor” to bme280 and the compatible to “bosch,bme280”. But that didn't help.

    Then I've read that the 

       compatible = "nordic,nrf-twi";

    might be a problem, but there was no such line. Perhaps that is the default. So, I added a line:

       compatible = "nordic,nrf-twim";

    and that did it. The issue seems to be the “nordic, nrf-twi”. I don't quite understand why, but now it works.

    &i2c0 {
        compatible = "nordic,nrf-twim";
        status = "okay";
        pinctrl-0 = <&i2c0_default>;
        pinctrl-1 = <&i2c0_sleep>;
        pinctrl-names = "default", "sleep";
        bme280: bme280@76 {
            compatible = "bosch,bme280";
            status = "okay";
            reg = <0x76>;
        };
    };
    ...
Reply
  • Hi there,

    I found a solution to my question. After reading numerous posts, one post got my attention.

    In the lesson 6 exercise 1 and in the solution, the overlay file nrf52840dk_nrf52840.overlay looks like

    &i2c0 {
        status = "okay";
        pinctrl-0 = <&i2c0_default>;
        pinctrl-1 = <&i2c0_sleep>;
        pinctrl-names = "default", “sleep”;
        bme280: bme280@76 {
            compatible = "bosch,bme280";
            status = "okay";
            reg = <0x76>;
        };
    };
    ...

    I changed “mysensor” to bme280 and the compatible to “bosch,bme280”. But that didn't help.

    Then I've read that the 

       compatible = "nordic,nrf-twi";

    might be a problem, but there was no such line. Perhaps that is the default. So, I added a line:

       compatible = "nordic,nrf-twim";

    and that did it. The issue seems to be the “nordic, nrf-twi”. I don't quite understand why, but now it works.

    &i2c0 {
        compatible = "nordic,nrf-twim";
        status = "okay";
        pinctrl-0 = <&i2c0_default>;
        pinctrl-1 = <&i2c0_sleep>;
        pinctrl-names = "default", "sleep";
        bme280: bme280@76 {
            compatible = "bosch,bme280";
            status = "okay";
            reg = <0x76>;
        };
    };
    ...
Children
Related