From f189c2a7b1dc38c9c10e48744de1f9d393bf5527 Mon Sep 17 00:00:00 2001 From: Kees Bakker Date: Thu, 30 Jun 2016 22:26:26 +0200 Subject: [PATCH] drivers/bmp180: during init retry getting ID because it may fail at first --- drivers/bmp180/bmp180.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/bmp180/bmp180.c b/drivers/bmp180/bmp180.c index 4ed56800ec55..5d8b40afee69 100644 --- a/drivers/bmp180/bmp180.c +++ b/drivers/bmp180/bmp180.c @@ -65,10 +65,12 @@ int bmp180_init(bmp180_t *dev, i2c_t i2c, uint8_t mode) /* Acquire exclusive access */ i2c_acquire(dev->i2c_dev); - /* Check sensor ID */ - char checkid; - i2c_write_byte(dev->i2c_dev, BMP180_ADDR, BMP180_REGISTER_ID); - i2c_read_reg(dev->i2c_dev, BMP180_ADDR, BMP180_REGISTER_ID, &checkid); + /* Check sensor ID (retry a few times, it may fail at first) */ + char checkid = 0; + for (size_t ix = 0; checkid == 0 && ix < 3; ++ix) { + i2c_write_byte(dev->i2c_dev, BMP180_ADDR, BMP180_REGISTER_ID); + i2c_read_reg(dev->i2c_dev, BMP180_ADDR, BMP180_REGISTER_ID, &checkid); + } if (checkid != 0x55) { DEBUG("[Error] Wrong device ID\n"); return -1;