How can I use two I2C modules?

Hi,

I want to measure CO2 in different locations using two similar CO2 sensor (MiCS-VZ-89TE). I can communicate with the sensor over I2C0.

But because two sensors have exactly the same I2C address, I cannot connect the second sensor to the same I2C0 module.

How can I activate I2C1 and where are the SDA and SCL pins of I2C1?

Parents Reply Children
  • Ok, thank you for answer. I connected the sensor to I2C1 pins P0.30 and P0.31, I cannot communicate with sensor.

    When I connect the sensor to I2C0 over P0.26 and P0.27, I can communicate.

    Is there any other settings in devicetree overlay or CONFIG variables?

    In my devicetree overlay I have:

    &i2c1 {
        status = "okay";
        vz89te1: vz89te@70 {
            compatible = "i2c-device";
            label = "MiCS-VZ-89TE-1";
            reg = <0x70>;
        };
    };

    status = "okay", because, as default in devicetree file, status = "okay" is commented, so I wrote it in overlay file.

  • Are you able to debug your driver to see where it fails when you select i2c1? It may also be a good idea to check the TWIM0/1 registers to see if they are being configured correctly.

  • I am able to debug it, but I don't know where to look/check.

    It seems TWIM0 and TWIM1 registers are configured correctly, at least pin numbers in PSEL are correct.
    But in Address (is it a register?) is wrong. At TWIM0 it is 0x70, and at TWIM1 it is 0.

    My devicetree overlay snippet:

    &i2c0 {
        vz89te0: vz89te0@70 {
            compatible = "i2c-device";
            label = "MiCS-VZ-89TE-0";
            reg = <0x70>;
        };
    };
    
    &i2c1 {
        status = "okay";
        vz89te1: vz89te1@70 {
            compatible = "i2c-device";
            label = "MiCS-VZ-89TE-1";
            reg = <0x70>;
        };
    };

  • The ADDRESS register is set when the i2c driver starts a transaction, so the fact that it is not set could indicate that something failed earlier in the init process.

    Do you have debug logs enabled (CONFIG_LOG=y) to see if the driver reports any errors?

  • When I activate logs, I receive the following error in NRF Terminal:

    [00:00:01.506,469] <err> i2c_nrfx_twi: Error on I2C line occurred for message 0

    I don't know what it means.

    In the nRF52840_DK_User_Guide_20201203 Document, P0.30 and P0.31 are mapped to AIN6 and AIN7. 
    But I found something in devicetree file nrf52840dk_nrf52840.dts. P0.30 and P0.31 are mapped to AIN6 and AIN7.

    I deactivated them but it still doesn't work.

    	arduino_adc: analog-connector {
    		compatible = "arduino,uno-adc";
    		#io-channel-cells = <1>;
    		io-channel-map = <0 &adc 1>;	/* A0 = P0.3 = AIN1 */
    		/* 		 <1 &adc 2>,	/* A1 = P0.4 = AIN2 */
    		/*		 <2 &adc 4>,	/* A2 = P0.28 = AIN4 */
    		/*		 <3 &adc 5>,	/* A3 = P0.29 = AIN5 */
    		/*       <4 &adc 6>,	/* A4 = P0.30 = AIN6 */
    		/*       <5 &adc 7>;	/* A5 = P0.31 = AIN7 */
    	};
    

Related