Powering Sensor-Device via GPIO and delay i2c communication - Devicetree implementation

Hello, 

My setup: nRF Connect SDK 1.9.1 + nRF52DK-nRF52805 + MPU9250 & MS5607 Sensors driven by gpio-i2c.

right now, I have eyerything working on my Prototype, except gpio sensor powering. 

I want the GPIOS to power the Sensors and I2C Busses. This should work in normal gpio mode regarding the current draw of both sensors. 

As you can see, I tried a little using vin-supply and supply-gpios in the DT.overlay  :

 #include <dt-bindings/gpio/gpio.h>

 / {
   
    
    zephyr,user {
        io-channels = <&adc 9>;
    };
	
	imu_pwr: imu-pwr-ctrl {
		compatible = "regulator-fixed";
		label = "imu-pwr-ctrl";
		regulator-name = "imu-pwr-ctrl";
		enable-gpios = <&gpio0 22 GPIO_ACTIVE_HIGH>;
	};
	
	pressure_pwr: pressure-pwr-ctrl {
		compatible = "regulator-fixed";
		label = "pressure-pwr-ctrl";
		regulator-name = "pressure-pwr-ctrl";
		enable-gpios = <&gpio0 23 GPIO_ACTIVE_HIGH>;
    };
 
     i2c1 {
         compatible = "gpio-i2c";
         sda-gpios = <&gpio0 26 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
         scl-gpios = <&gpio0 27 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
         status = "okay";
         clock-frequency = < 100000 >;
         #address-cells = <1>;
         #size-cells = <0>;
         label = "i2c1-gpio0";
        
         mpu9250@68 {
             compatible = "invensense,mpu9250";
             gyro-sr-div = <0>;
             gyro-dlpf = <250>;
             gyro-fs = <2000>;
             accel-fs = <16>;
             accel-dlpf = "218.1";
             reg = <0x68 >;
             label = "MPU9250";
             status = "okay";
             //supply-gpios = < &gpio0 22 GPIO_ACTIVE_HIGH >;
             //vin-supply = < &imu_pwr >;
         };
                    
     };
 
     i2c2 {
         compatible = "gpio-i2c";
         sda-gpios = <&gpio0 24 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
         scl-gpios = <&gpio0 25 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
         status = "okay";
         clock-frequency = < 100000 >;
         #address-cells = <1>;
         #size-cells = <0>;
         label = "i2c2-gpio0";
         ms5607@76 {
             compatible = "meas,ms5607";
             reg = <0x76>;
             label = "MS5607-2";
             //supply-gpios = < &gpio0 23 GPIO_ACTIVE_HIGH >;
             //vin-supply = < &pressure_pwr >;
         };  
     };
     
 };
     
 //status auf disabled setzen zwingend erforderlich, sonst funktioniert der gpio-i2c Treiber nicht
 &i2c0 {
     status = "disabled";
 };
 
 &adc {
     status = "okay";
 };

 &gpio0 {
    status = "okay";
 };
 

I need an advice, how to manage this in the right way. Further I want do add a delay of 10ms because of the initial power spike and sensor initialisation. 
Therefore I wanted to use  'i2c-gpio,timeout-ms', but this isn't supported in the used SDK/Zephyr version I think?

Best regards, 

Jonas

Parents Reply Children
  • thanks for your quick reply  

    I did the same thing that you did, and put a 1sec startup delay like this, but when I check the line, the device is being initialized without waiting 1 sec. I was wondering did you need to edit your sensor yaml file? do you need to add anything related to the regulator?

    1. regulator driver in prj.conf
    CONFIG_REGULATOR=y

    3. I use 'vin-supply' in the sensor nodes 

    	mux:tca9546a@70 {
    		compatible = "ti,tca9546a";
    		reg = <0x70>;
    		status = "okay";
    		#address-cells = <1>;
    		#size-cells = <0>;	
    		vin-supply = <&pwrout0>;
    		
    		chnl0:mux_i2c@0 {
    			compatible = "ti,tca9546a-channel";
    			reg = <0>;
    			status = "okay";
    			#address-cells = <1>;
    			#size-cells = <0>;
    			yic_gnss:yic91009ebgg@42 {
    				compatible = "yic,yic91009ebgg";
    				reg = <0x42>;
    				vin-supply = < &pwrout1 >;
    			};
    		};
    		
    		};
    2. DTS entrys like in this case with 'regulator-boot-on;'
     pwrout0: pwrout_0 {
                compatible = "regulator-fixed";
    			regulator-name = "accel-pwr-ctrl";
                enable-gpios = <&gpio0 31 GPIO_ACTIVE_HIGH>;
                startup-delay-us = < 1000000 >;
                regulator-boot-on;
            };
            pwrout1: pwrout_1 {
                compatible = "regulator-fixed";
                regulator-name = "press-pwr-ctrl";
                enable-gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>;
                startup-delay-us = < 1000000 >;
                regulator-boot-on;
    
            };
  • No, I have not edited the yaml file. I have tested also with this startup delay but without success. Maybe you can edit the SENSOR_DEVICE_DT_DEFINE() in your device driver. 

    Check Initialization levels in device driver model: https://docs.zephyrproject.org/3.1.0/kernel/drivers/index.html

    further you maybe can ask on the zephyr discord server

Related