This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

connect sdk twi startup problems

I have connected a BM680 sensor on a BL654 (NRF52840) via I2C. I have connected the power to the BME680 on a switchable power rail. I need to power this rail with a GPIO pin on the NRF52. Also the I2C pins are connected to a GPIO pin of the NRF52840 to save power in sleep conditions. I have the following output in Zephyr.

I get an error the first boot cycle and I suspect the I2C is loaded before the power is applied to the sensor and the I2C pullup resistors. Because when I reload the code with a debugger the device works immediatly because the power and pull-ups are connected at startup. I have looked around but I can not find a way to set a gpio pin before the startup of the I2C. Is there a way to solve this issue?

*** Booting Zephyr OS build v2.4.0-ncs2  ***
[00:00:00.915,863] <err> i2c_nrfx_twi: Error on I2C line occurred for message 0
Hello! I'm running Zephyr v1 2.4.0 on nrf52840dk_nrf52840, a arm board.

*** Booting Zephyr OS build v2.4.0-ncs2  ***
Hello! I'm running Zephyr v1 2.4.0 on nrf52840dk_nrf52840, a arm board.

Found device "BME680"
Device 0x2000015c name is BME680
T: 17.250000; P: 100.274000; H: 61.923000; G: 88975.000000
T: 17.230000; P: 100.278000; H: 61.952000; G: 178953.000000
T: 17.260000; P: 100.276000; H: 61.890000; G: 217160.000000
T: 17.270000; P: 100.276000; H: 61.838000; G: 235988.000000

Parents
  • Just an update, for now I seem to have "solved" this issue by adding a bit of code to the BME680 to write the GPIO pins high. But this is clearly not the way to go. Does anyone have an idea to make a driver or a piece of code that will run before the sensor startup?

    static int pwr_ctrl_init()
    {
    	const struct device *gpio;
    	const char *port = DT_LABEL(DT_NODELABEL(gpio0));
    	gpio = device_get_binding(port);
    	if (!gpio) {
    		printk("Could not bind device \"%s\"\n", port);
    		return -ENODEV;
    	}
    
    	gpio_pin_configure(gpio, VDD_PWR_CTRL_GPIO_PIN, GPIO_OUTPUT_HIGH);
    	gpio_pin_configure(gpio, VDD_PWR_PULLUP_GPIO_PIN, GPIO_OUTPUT_HIGH);
    
    	k_sleep(K_MSEC(10)); /* Wait for the rail to come up and stabilize */
    
    	return 0;
    }

Reply
  • Just an update, for now I seem to have "solved" this issue by adding a bit of code to the BME680 to write the GPIO pins high. But this is clearly not the way to go. Does anyone have an idea to make a driver or a piece of code that will run before the sensor startup?

    static int pwr_ctrl_init()
    {
    	const struct device *gpio;
    	const char *port = DT_LABEL(DT_NODELABEL(gpio0));
    	gpio = device_get_binding(port);
    	if (!gpio) {
    		printk("Could not bind device \"%s\"\n", port);
    		return -ENODEV;
    	}
    
    	gpio_pin_configure(gpio, VDD_PWR_CTRL_GPIO_PIN, GPIO_OUTPUT_HIGH);
    	gpio_pin_configure(gpio, VDD_PWR_PULLUP_GPIO_PIN, GPIO_OUTPUT_HIGH);
    
    	k_sleep(K_MSEC(10)); /* Wait for the rail to come up and stabilize */
    
    	return 0;
    }

Children
No Data
Related