Skip to content

Conversation

@leonardp
Copy link
Contributor

@leonardp leonardp commented Sep 27, 2021

This Pull request adds support for the BME680 SPI Interface.
It is mostly analogous to the BME280.

Signed-off-by: Leonard Pollak [email protected]

@github-actions github-actions bot added area: Devicetree area: Devicetree Binding PR modifies or adds a Device Tree binding area: Tests Issues related to a particular existing or missing test labels Sep 27, 2021
@leonardp leonardp changed the title Add support for BME680s SPI Interface Add support for BME680 SPI Interface Sep 27, 2021
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a condition of the device instance? i.e., would this work if you had a SPI instance and an I2C instance in your application?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. It probably won't work..
I could add a new member to the bme680_config (e.g. bus_type) and then check for that.
Do you think that would make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not fold this into the individual bus_io->read routines as needed instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is roughly what I ended up doing.
I made a separate function that does the mem page switching and I am also calling it from the bus_io->write routine.

@MaureenHelm MaureenHelm requested a review from teburd October 28, 2021 15:07
teburd
teburd previously requested changes Oct 28, 2021
Copy link
Contributor

@teburd teburd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned the compile ifdef for setting the mem page when using SPI seems an issue to me as well, everything else looks great

@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Jan 10, 2022
@leonardp
Copy link
Contributor Author

Sorry for shelving this for so long without notice.
Thanks for the reviews so far.
I will (most probably) be able to get this done by the end of next week.

@github-actions github-actions bot removed the Stale label Jan 11, 2022
@leonardp leonardp force-pushed the bme680_spi branch 3 times, most recently from 17783e0 to 8de7551 Compare January 21, 2022 17:52
@leonardp
Copy link
Contributor Author

I've updated the PR and tested it with I2C and SPI instance enabled simultaneously.

@leonardp leonardp force-pushed the bme680_spi branch 2 times, most recently from 5eedfb4 to a12865e Compare January 22, 2022 07:47
@leonardp
Copy link
Contributor Author

I split the pull request into 4 commits as suggested by @mbolivar-nordic.
I hope everything is in order now.
Thanks for all the reviews so far!

Copy link
Contributor

@mbolivar-nordic mbolivar-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, that was indeed easier to review

Comment on lines 364 to 373
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining. In that case I think it would be a little better to write it something like this:

static inline bool bme680_is_on_spi(struct device *dev)
{
	const struct bme680_config *config = dev->config;

	return config->bus_io == &bme680_bus_io_spi;
}

/* ... */

#if BME680_BUS_SPI
	if (bme680_is_on_spi(dev)) {
		err = ...;
		if (err < 0) {
			return err;
		}
	}
#endif

IMO it is a bit better to have the I2C devices initialize the same way always, regardless of whether a SPI device happens to be in the same system. It may ease debugging in some cases and it definitely enhances consistency.

But it's not a blocking request; just please consider it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking another look at it and giving some more insight on that matter.

To have it consistent across all possible configurations wouldn't it make sense to
remove the #if BME680_BUS_SPI directive aswell?

I have prepared the change as suggested by you (without the #if). If that makes sense to you I can push them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a fair point -- if it's safe to do regardless of bus type, might as well be consistent on all of them. Given the ifdef, I was assuming there was a reason to prefer not to do it on I2C, but if there isn't, then I'm fine either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it was probably me just over-complicating things -.-;
I pushed the changes, this way it is definitely easier on the eyes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...disregard that.. the directives are needed or else it won't build for I2C, obviously..
Sorry for the noise.

@leonardp
Copy link
Contributor Author

@teburd would you take another look?

@mbolivar-nordic mbolivar-nordic added this to the v3.1.0 milestone Feb 23, 2022
MaureenHelm
MaureenHelm previously approved these changes Feb 23, 2022
@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Apr 25, 2022
@MaureenHelm
Copy link
Member

I think this PR got lost in the shuffle while the merge window was closed for the 3.0 release.

@leonardp will you please rebase and resolve the merge conflict?

@teburd teburd dismissed their stale review April 25, 2022 17:18

Out of date

@github-actions github-actions bot removed the Stale label Apr 26, 2022
Leonard Pollak added 4 commits April 28, 2022 13:02
This fixes the constant for the mem page and replaces a
magic number with the already defined `BME680_LEN_COEFF2` constant.

Signed-off-by: Leonard Pollak <[email protected]>
Consolidate the initialization routines and change the include guard to
conform with the coding guidelines as a preparation for the following
commits which add support for the SPI interface.

Signed-off-by: Leonard Pollak <[email protected]>
This enables the SPI interface for the BME680 sensor driver.

Signed-off-by: Leonard Pollak <[email protected]>
Add BME680 (SPI) sensor driver to build_all tests.

Signed-off-by: Leonard Pollak <[email protected]>
@carlescufi
Copy link
Member

@MaureenHelm @mbolivar-nordic I rebased this, please re-ack.

@carlescufi carlescufi merged commit f7171e2 into zephyrproject-rtos:main Apr 28, 2022
@Senso4sLab
Copy link

Senso4sLab commented Mar 20, 2024

I tested bme680 sample with SPI and I got the following error bme680: Bad BME680 chip id: 0x0. I used the following prj.conf settings

&spi0 {
	compatible = "nordic,nrf-spi";	
	status = "okay";
	pinctrl-0 = <&spi0_default>;
	pinctrl-1 = <&spi0_sleep>;
	pinctrl-names = "default", "sleep";
    cs-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>,
               <&gpio1 6 GPIO_ACTIVE_LOW>;              
    
    bme6800:bme680_0@0 {
		compatible = "bosch,bme680";
        status = "okay";
		reg = <0>;
        label="bme680_1";
		spi-max-frequency = <1000000>;        
	};
    bme6801:bme680_1@1 {
		compatible = "bosch,bme680";
        status = "okay";
		reg = <1>;
        label="bme680_2";
		spi-max-frequency = <1000000>; 
	};
     
};

I did some additional tests and I found out that if both bme 680 chips were connected to the board none of them was detected. If only one bme 680 chip is connected to the board, the address is figured out successfully. Based on this observation I assumed that something was wrong with the implementation details of the bme 680 library.

I will appreciate for help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Build System area: Devicetree Binding PR modifies or adds a Device Tree binding area: Devicetree area: Sensors Sensors area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants