Skip to content

Commit

Permalink
add i2c timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-goddard committed Jan 9, 2025
1 parent 61ad3e3 commit b0636ac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bmp388.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ bool BMP388::read_data(float *altitude, float *temperature, float sea_level_pres
}

BMP3_INTF_RET_TYPE BMP388::i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr) {
if (i2c_write_blocking(i2c0, BMP388_ADDR, &reg_addr, 1, true) < 1) {
if (i2c_write_timeout_us(i2c0, BMP388_ADDR, &reg_addr, 1, true, BYTE_TIMEOUT_US) < 1) {
return 1;
}
if (i2c_read_blocking(i2c0, BMP388_ADDR, reg_data, len, false) < 1) {
if (i2c_read_timeout_us(i2c0, BMP388_ADDR, reg_data, len, false, BYTE_TIMEOUT_US) < 1) {
return 1;
}
return BMP3_INTF_RET_SUCCESS;
Expand All @@ -87,7 +87,7 @@ BMP3_INTF_RET_TYPE BMP388::i2c_write(uint8_t reg_addr, const uint8_t *reg_data,
buf[0] = reg_addr;
memcpy(&buf[1], reg_data, len);

if (i2c_write_blocking(i2c0, BMP388_ADDR, buf, len + 1, false) < 1) {
if (i2c_write_timeout_us(i2c0, BMP388_ADDR, buf, len + 1, false, BYTE_TIMEOUT_US) < 1) {
return 1;
}
return BMP3_INTF_RET_SUCCESS;
Expand Down
2 changes: 2 additions & 0 deletions bmp388.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#define BMP388_ADDR (0x77)

#define BYTE_TIMEOUT_US (1500)

/**
* Representation of the BMP388 sensor.
* Uses the Bosch Sensortec BMP3 API under the hood.
Expand Down

0 comments on commit b0636ac

Please sign in to comment.