mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 00:05:33 +03:00
Restore zero i2c addr when detect failed
This commit is contained in:
parent
f00b885799
commit
c5f488ed07
3 changed files with 25 additions and 4 deletions
|
@ -169,6 +169,8 @@ bool bmp085Detect(const bmp085Config_t *config, baroDev_t *baro)
|
||||||
{
|
{
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
bool ack;
|
bool ack;
|
||||||
|
bool defaultAddressApplied = false;
|
||||||
|
|
||||||
#if defined(BARO_EOC_GPIO)
|
#if defined(BARO_EOC_GPIO)
|
||||||
IO_t eocIO = IO_NONE;
|
IO_t eocIO = IO_NONE;
|
||||||
#endif
|
#endif
|
||||||
|
@ -200,6 +202,7 @@ bool bmp085Detect(const bmp085Config_t *config, baroDev_t *baro)
|
||||||
if ((busdev->bustype == BUSTYPE_I2C) && (busdev->busdev_u.i2c.address == 0)) {
|
if ((busdev->bustype == BUSTYPE_I2C) && (busdev->busdev_u.i2c.address == 0)) {
|
||||||
// Default address for BMP085
|
// Default address for BMP085
|
||||||
busdev->busdev_u.i2c.address = BMP085_I2C_ADDR;
|
busdev->busdev_u.i2c.address = BMP085_I2C_ADDR;
|
||||||
|
defaultAddressApplied = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ack = bmp085ReadRegister(busdev, BMP085_CHIP_ID__REG, 1, &data); /* read Chip Id */
|
ack = bmp085ReadRegister(busdev, BMP085_CHIP_ID__REG, 1, &data); /* read Chip Id */
|
||||||
|
@ -234,6 +237,10 @@ bool bmp085Detect(const bmp085Config_t *config, baroDev_t *baro)
|
||||||
|
|
||||||
BMP085_OFF;
|
BMP085_OFF;
|
||||||
|
|
||||||
|
if (defaultAddressApplied) {
|
||||||
|
busdev->busdev_u.i2c.address = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,18 +127,23 @@ bool bmp280Detect(baroDev_t *baro)
|
||||||
delay(20);
|
delay(20);
|
||||||
|
|
||||||
busDevice_t *busdev = &baro->busdev;
|
busDevice_t *busdev = &baro->busdev;
|
||||||
|
bool defaultAddressApplied = false;
|
||||||
|
|
||||||
bmp280BusInit(busdev);
|
bmp280BusInit(busdev);
|
||||||
|
|
||||||
if ((busdev->bustype == BUSTYPE_I2C) && (busdev->busdev_u.i2c.address == 0)) {
|
if ((busdev->bustype == BUSTYPE_I2C) && (busdev->busdev_u.i2c.address == 0)) {
|
||||||
// Default address for BMP280
|
// Default address for BMP280
|
||||||
busdev->busdev_u.i2c.address = BMP280_I2C_ADDR;
|
busdev->busdev_u.i2c.address = BMP280_I2C_ADDR;
|
||||||
|
defaultAddressApplied = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bmp280ReadRegister(busdev, BMP280_CHIP_ID_REG, 1, &bmp280_chip_id); /* read Chip Id */
|
bmp280ReadRegister(busdev, BMP280_CHIP_ID_REG, 1, &bmp280_chip_id); /* read Chip Id */
|
||||||
|
|
||||||
if (bmp280_chip_id != BMP280_DEFAULT_CHIP_ID) {
|
if (bmp280_chip_id != BMP280_DEFAULT_CHIP_ID) {
|
||||||
bmp280BusDeinit(busdev);
|
bmp280BusDeinit(busdev);
|
||||||
|
if (defaultAddressApplied) {
|
||||||
|
busdev->busdev_u.i2c.address = 0;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,7 @@ bool ms5611Detect(baroDev_t *baro)
|
||||||
{
|
{
|
||||||
uint8_t sig;
|
uint8_t sig;
|
||||||
int i;
|
int i;
|
||||||
|
bool defaultAddressApplied = false;
|
||||||
|
|
||||||
delay(10); // No idea how long the chip takes to power-up, but let's make it 10ms
|
delay(10); // No idea how long the chip takes to power-up, but let's make it 10ms
|
||||||
|
|
||||||
|
@ -132,11 +133,11 @@ bool ms5611Detect(baroDev_t *baro)
|
||||||
if ((busdev->bustype == BUSTYPE_I2C) && (busdev->busdev_u.i2c.address == 0)) {
|
if ((busdev->bustype == BUSTYPE_I2C) && (busdev->busdev_u.i2c.address == 0)) {
|
||||||
// Default address for MS5611
|
// Default address for MS5611
|
||||||
busdev->busdev_u.i2c.address = MS5611_I2C_ADDR;
|
busdev->busdev_u.i2c.address = MS5611_I2C_ADDR;
|
||||||
|
defaultAddressApplied = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ms5611ReadCommand(busdev, CMD_PROM_RD, 1, &sig) || sig == 0xFF) {
|
if (!ms5611ReadCommand(busdev, CMD_PROM_RD, 1, &sig) || sig == 0xFF) {
|
||||||
ms5611BusDeinit(busdev);
|
goto fail;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ms5611_reset(busdev);
|
ms5611_reset(busdev);
|
||||||
|
@ -147,8 +148,7 @@ bool ms5611Detect(baroDev_t *baro)
|
||||||
|
|
||||||
// check crc, bail out if wrong - we are probably talking to BMP085 w/o XCLR line!
|
// check crc, bail out if wrong - we are probably talking to BMP085 w/o XCLR line!
|
||||||
if (ms5611_crc(ms5611_c) != 0) {
|
if (ms5611_crc(ms5611_c) != 0) {
|
||||||
ms5611BusDeinit(busdev);
|
goto fail;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO prom + CRC
|
// TODO prom + CRC
|
||||||
|
@ -161,6 +161,15 @@ bool ms5611Detect(baroDev_t *baro)
|
||||||
baro->calculate = ms5611_calculate;
|
baro->calculate = ms5611_calculate;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
fail:;
|
||||||
|
ms5611BusDeinit(busdev);
|
||||||
|
|
||||||
|
if (defaultAddressApplied) {
|
||||||
|
busdev->busdev_u.i2c.address = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ms5611_reset(busDevice_t *busdev)
|
static void ms5611_reset(busDevice_t *busdev)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue