Skip to content

Avoid calling begin more than is required #36 #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/SparkFunBME280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ bool BME280::beginSPI(uint8_t csPin)
settings.chipSelectPin = csPin;
settings.commInterface = SPI_MODE;

if(begin() == 0x58) return(true); //Begin normal init with these settings. Should return chip ID of 0x58 for BMP
if(begin() == 0x60) return(true); //Begin normal init with these settings. Should return chip ID of 0x60 for BME
uint8_t chipID = begin();

if(chipID == 0x58) return(true); //Begin normal init with these settings. Should return chip ID of 0x58 for BMP
if(chipID == 0x60) return(true); //Begin normal init with these settings. Should return chip ID of 0x60 for BME
return(false);
}

Expand All @@ -171,10 +173,12 @@ bool BME280::beginI2C(TwoWire &wirePort)
_wireType = HARD_WIRE;

settings.commInterface = I2C_MODE;

//settings.I2CAddress = 0x77; //We assume user has set the I2C address using setI2CAddress()
if(begin() == 0x58) return(true); //Begin normal init with these settings. Should return chip ID of 0x58 for BMP
if(begin() == 0x60) return(true); //Begin normal init with these settings. Should return chip ID of 0x60 for BME

uint8_t chipID = begin();

if(chipID == 0x58) return(true); //Begin normal init with these settings. Should return chip ID of 0x58 for BMP
if(chipID == 0x60) return(true); //Begin normal init with these settings. Should return chip ID of 0x60 for BME
return(false);
}

Expand All @@ -188,8 +192,10 @@ bool BME280::beginI2C(SoftwareWire& wirePort)
settings.commInterface = I2C_MODE;
//settings.I2CAddress = 0x77; //We assume user has set the I2C address using setI2CAddress()

if(begin() == 0x58) return(true); //Begin normal init with these settings. Should return chip ID of 0x58 for BMP
if(begin() == 0x60) return(true); //Begin normal init with these settings. Should return chip ID of 0x60 for BME
uint8_t chipID = begin();

if(chipID == 0x58) return(true); //Begin normal init with these settings. Should return chip ID of 0x58 for BMP
if(chipID == 0x60) return(true); //Begin normal init with these settings. Should return chip ID of 0x60 for BME
return(false);
}
#endif
Expand Down