Skip to content
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

Fix occasional problems with SPL06 #16964

Merged
merged 1 commit into from
Mar 24, 2021
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
17 changes: 14 additions & 3 deletions libraries/AP_Baro/AP_Baro_SPL06.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,20 @@ bool AP_Baro_SPL06::_init()
_dev->set_speed(AP_HAL::Device::SPEED_HIGH);

uint8_t whoami;
if (!_dev->read_registers(SPL06_REG_CHIP_ID, &whoami, 1) ||
whoami != SPL06_CHIP_ID) {
// not a SPL06

// Sometimes SPL06 has init problems, that's due to failure of reading using SPI for the first time. The SPL06 is a dual
// protocol sensor(I2C and SPI), sometimes it takes one SPI operation to convert it to SPI mode after it starts up.
bool is_SPL06 = false;

for (uint8_t i=0; i<5; i++) {
if (_dev->read_registers(SPL06_REG_CHIP_ID, &whoami, 1) &&
whoami == SPL06_CHIP_ID) {
is_SPL06=true;
break;
}
}

if(!is_SPL06) {
return false;
}

Expand Down