Multiple devices with the same address on two different I2C buses

Hello, I have a minor problem with starting up i2c0 and i2c1. I am trying to run a scanner in the sample code that will print out the addresses connected to these buses. I am using an SRT40 sensor with address 0x44. This scan only works for the i2c0 bus without any problems.


Here is the code:

overlay:
/ {
    aliases {
        i2c0 = &i2c0;
        i2c1 = &i2c1;
    };
};


&spi0 {
    status = "disabled"; 
};

&spi1 {
    status = "disabled"; 
};

&i2c0 {
    compatible = "nordic,nrf-twim";
    status = "okay";
    scl-pin = <26>; 
    sda-pin = <27>; 
    clock-frequency = <I2C_BITRATE_STANDARD>;  
};

&i2c1 {
    compatible = "nordic,nrf-twim";
    status = "okay"; 
    scl-pin = <28>;
    sda-pin = <29>;  
    clock-frequency = <I2C_BITRATE_STANDARD>; 
};




prj.conf:

CONFIG_I2C=y
CONFIG_I2C_NRFX=y


main:
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/sys/printk.h>

#define I2C0_NODE DT_NODELABEL(i2c0)
#define I2C1_NODE DT_NODELABEL(i2c1)

const struct device *i2c0_dev = DEVICE_DT_GET(I2C0_NODE);
const struct device *i2c1_dev = DEVICE_DT_GET(I2C1_NODE);

void scan_i2c_bus(const struct device *i2c_dev, const char *bus_name) {
    if (!device_is_ready(i2c_dev)) {
        printk("I2C %s is not ready!\n", bus_name);
        return;
    }

    printk("Scanning %s...\n", bus_name);
    for (uint8_t addr = 0x08; addr <= 0x77; addr++) {
        uint8_t dummy;
        struct i2c_msg msg = {
            .buf = &dummy,
            .len = 1,
            .flags = I2C_MSG_WRITE | I2C_MSG_STOP,
        };

        if (i2c_transfer(i2c_dev, &msg, 1, addr) == 0) {
            printk("Found device at 0x%02X on %s\n", addr, bus_name);
        }
    }
}

int main(void) {
    printk("\n🚀 Starting I2C scan on nRF52840\n");

    scan_i2c_bus(i2c0_dev, "I2C0");
    scan_i2c_bus(i2c1_dev, "I2C1");

    printk("12C scan completed.\n");
    return 0;
}




I really don't know why it doesn't want to find i2c1, according to the documentation I turned off the spi1 peripherals. I also tried adding this to prj.conf:
CONFIG_I2C=y
CONFIG_I2C_NRFX=y
CONFIG_NRFX_TWIM1=y      
CONFIG_NRFX_TWIM=y        
CONFIG_I2C_NRFX_TWIM=y    
CONFIG_PINCTRL=y        
CONFIG_LOG=y
CONFIG_STDOUT_CONSOLE=y

after this prj I get this error:

error: NRFX_TWIM (defined at C:/ncs/v2.9.0/zephyr/modules/hal_nordic\nrfx/Kconfig:842,
modules\hal_nordic\nrfx/Kconfig:842) is assigned in a configuration file, but is not directly user-
configurable (has no prompt). It gets its value indirectly from...Code

I use Zephyr OS, nRF Connect SDK v2.9.0
I will be glad for any help and thanks in advance :)


Parents Reply Children
Related