BMP280: Crude workaround for detecting chip presence
This commit is contained in:
parent
2f0f6a01f2
commit
3dcf412a02
17
src/bmp280.c
17
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;
|
||||
|
|
Loading…
Reference in a new issue