I2C communication with two NRF DK

Hi,

I want to make an I2C communication with an NRF5340 DK as Master and an NRF52840 as Slave, but all the example i found in I2C communication it use the slave adress to communicate,

But i don't know my NRF52840 DK I2C adress, is there a way to make this communication possible ? 

Thank you for your help,

Best Regards,

Daroussi 

Parents
  • For the master config i have this : 

    prj.conf : 

    #
    # Copyright (c) 2016 Intel Corporation
    #
    # SPDX-License-Identifier: Apache-2.0
    #
    
    # STEP 2 - Enable the I2C driver
    CONFIG_I2C=y
    # STEP 4.2 - Enable floating point format specifiers
    CONFIG_CBPRINTF_FP_SUPPORT=y
    
    

    my overlay: 

    // To get started, press Ctrl+Space to bring up the completion menu and view the available nodes.
    // For more help, browse the DeviceTree documentation at https://docs.zephyrproject.org/latest/guides/dts/index.html
    
    &i2c0 {
        status = "okay";
        pinctrl-0 = <&i2c0_default>;
    	pinctrl-1 = <&i2c0_sleep>;
        pinctrl-names = "default", "sleep";
        mysensor: mysensor@77{
            compatible = "i2c-device";
            status = "okay";
            reg = < 0x77 >;
        };
    };
    
    &pinctrl {
    	/omit-if-no-ref/ i2c0_default: i2c0_default {
    		group1  {
    			psels = <NRF_PSEL(TWIM_SCL, 1, 14)>,
    					<NRF_PSEL(TWIM_SDA, 1, 15)>;
    		};
    	};
    
    	/omit-if-no-ref/ i2c0_sleep: i2c0_sleep {
    		group1  {
    			psels = <NRF_PSEL(TWIM_SCL, 1, 14)>,
    					<NRF_PSEL(TWIM_SDA, 1, 15)>;
    			low-power-enable;
    		};
    	};
    };

    my main.c

    /*
     * Copyright (c) 2016 Intel Corporation
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr/kernel.h>
    #include <zephyr/device.h>
    #include <zephyr/devicetree.h>
    /* STEP 3 - Include the header file of the I2C API */
    #include <zephyr/drivers/i2c.h>
    /* STEP 4.1 - Include the header file of printk() */
    #include <zephyr/sys/printk.h>
    /* 1000 msec = 1 sec */
    #define SLEEP_TIME_MS 1000
    
    /* STEP 6 - Get the node identifier of the sensor */
    #define I2C_NODE DT_NODELABEL(mysensor)
    
    
    
    
    
    int main(void)
    {
    	static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(I2C_NODE);
    
    	if (!device_is_ready(dev_i2c.bus)) {
    		printk("I2C bus %s is not ready!\n", dev_i2c.bus->name);
    		return -1;
    	}
    
    	
    
    	uint8_t data;
    	int ret = i2c_read_dt(&dev_i2c, &data, sizeof(data));
    	if(ret != 0){
    		printk("Failed to read from I2C device address");
    	}
    
    
    }
    

Reply
  • For the master config i have this : 

    prj.conf : 

    #
    # Copyright (c) 2016 Intel Corporation
    #
    # SPDX-License-Identifier: Apache-2.0
    #
    
    # STEP 2 - Enable the I2C driver
    CONFIG_I2C=y
    # STEP 4.2 - Enable floating point format specifiers
    CONFIG_CBPRINTF_FP_SUPPORT=y
    
    

    my overlay: 

    // To get started, press Ctrl+Space to bring up the completion menu and view the available nodes.
    // For more help, browse the DeviceTree documentation at https://docs.zephyrproject.org/latest/guides/dts/index.html
    
    &i2c0 {
        status = "okay";
        pinctrl-0 = <&i2c0_default>;
    	pinctrl-1 = <&i2c0_sleep>;
        pinctrl-names = "default", "sleep";
        mysensor: mysensor@77{
            compatible = "i2c-device";
            status = "okay";
            reg = < 0x77 >;
        };
    };
    
    &pinctrl {
    	/omit-if-no-ref/ i2c0_default: i2c0_default {
    		group1  {
    			psels = <NRF_PSEL(TWIM_SCL, 1, 14)>,
    					<NRF_PSEL(TWIM_SDA, 1, 15)>;
    		};
    	};
    
    	/omit-if-no-ref/ i2c0_sleep: i2c0_sleep {
    		group1  {
    			psels = <NRF_PSEL(TWIM_SCL, 1, 14)>,
    					<NRF_PSEL(TWIM_SDA, 1, 15)>;
    			low-power-enable;
    		};
    	};
    };

    my main.c

    /*
     * Copyright (c) 2016 Intel Corporation
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr/kernel.h>
    #include <zephyr/device.h>
    #include <zephyr/devicetree.h>
    /* STEP 3 - Include the header file of the I2C API */
    #include <zephyr/drivers/i2c.h>
    /* STEP 4.1 - Include the header file of printk() */
    #include <zephyr/sys/printk.h>
    /* 1000 msec = 1 sec */
    #define SLEEP_TIME_MS 1000
    
    /* STEP 6 - Get the node identifier of the sensor */
    #define I2C_NODE DT_NODELABEL(mysensor)
    
    
    
    
    
    int main(void)
    {
    	static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(I2C_NODE);
    
    	if (!device_is_ready(dev_i2c.bus)) {
    		printk("I2C bus %s is not ready!\n", dev_i2c.bus->name);
    		return -1;
    	}
    
    	
    
    	uint8_t data;
    	int ret = i2c_read_dt(&dev_i2c, &data, sizeof(data));
    	if(ret != 0){
    		printk("Failed to read from I2C device address");
    	}
    
    
    }
    

Children
No Data
Related