From 3dcf412a02bb9f12c5ec4a7151523962f508906b Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Sat, 8 Oct 2022 21:48:43 +0200 Subject: [PATCH] BMP280: Crude workaround for detecting chip presence --- src/bmp280.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/bmp280.c b/src/bmp280.c index e26e70c..1526fb8 100644 --- a/src/bmp280.c +++ b/src/bmp280.c @@ -45,6 +45,23 @@ bool bmp280_init(void) uint8_t rdata[32]; uint8_t wsize, rsize; + // check for chip presence by accessing the chip id register (not a proper read!) + i2c_set_7bit_address(I2C1, BMP280_7BIT_ADDR); + i2c_set_write_transfer_dir(I2C1); + i2c_set_bytes_to_transfer(I2C1, 1); + i2c_enable_autoend(I2C1); + i2c_send_start(I2C1); + + uint32_t timeout = 1000000; + while(--timeout && !i2c_transmit_int_status(I2C1)); // wait for the address transfer to complete + + i2c_send_data(I2C1, 0xD0); + + if((timeout == 0) || i2c_nack(I2C1)) { + // something went wrong during communication + goto err_out; + } + // read the chip ID wsize = 0; wdata[wsize++] = 0xD0;