I have the BMP388 from SparkFun connected to the Raspberry Pi Pico. This chip has Vin, 3V0, GND, SCK, SDO, SDI, CS, and INT pinouts. I have Vin = 5v, GND, SCK connected to pico, SDO grounded for default address, and SDI connected to the pico. I'm using the Bosch API provided on github and have defined write, read, and delay functions that interface with the pico. For some reason, when I'm reading in a loop, my temperature (plausible) and pressure readings (implausible) never change. I have observed the flowchart in the datasheet regarding measurement timings and I have added more than enough delay to ensure accurate readings but there must be something wrong. Below is sample code used to try and get repeated measurements from the sensor. I've tried various oversampling settings, ODR frequencies, and varying pico I2C frequencies as well. // Hardware address for BMP 388
static uint8_t addr = 0x76;
// Constructor: performs all required pre-setup tasks.
BMP::BMP() {
int8_t result = 0;
int i = 0;
// set up i2c stuff on the Pico
i2c_init(i2c0, 40*1000);
gpio_set_function(PICO_BMP_I2C_SDA_PIN, GPIO_FUNC_I2C);
gpio_set_function(PICO_BMP_I2C_SCL_PIN, GPIO_FUNC_I2C);
// Set the BMP388 struct to use I2C and self-defined read/write/delay funcs
bmp388.intf = BMP3_I2C_INTF;
bmp388.delay_us = (bmp3_delay_us_fptr_t)&bmpDelay;
bmp388.read = (bmp3_read_fptr_t)&bmpRead;
bmp388.write = (bmp3_write_fptr_t)&bmpWrite;
// perform selftest for error checking
//printf("Selftest result is: %d\n", bmp3_selftest_check(&bmp388));
//fflush(stdout);
/* Variable used to select the sensor component */
uint8_t sensor_comp;
// Use Pressure and Temperature readings
sensor_comp = BMP3_PRESS | BMP3_TEMP;
/* Used to select the settings user needs to change */
uint16_t settings_sel;
/* Variable used to store the compensated data */
struct bmp3_data data = { 0 };
result = bmp3_soft_reset(&bmp388);
bmp388.delay_us(40000, bmp388.intf_ptr);
result = bmp3_init(&bmp388);
bmp388.delay_us(40000, bmp388.intf_ptr);
//validate_trimming_param(&bmp388);
bmp388.settings.press_en = BMP3_ENABLE;
bmp388.settings.temp_en = BMP3_ENABLE;
bmp388.settings.odr_filter.press_os = BMP3_OVERSAMPLING_8X;
bmp388.settings.odr_filter.temp_os = BMP3_OVERSAMPLING_2X;
bmp388.settings.odr_filter.iir_filter = BMP3_IIR_FILTER_COEFF_15;
bmp388.settings.odr_filter.odr = BMP3_ODR_50_HZ;
settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_TEMP_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR;
result = bmp3_set_sensor_settings(settings_sel, &bmp388);
bmp388.delay_us(40000, bmp388.intf_ptr);
printf("The sensor set result was %d\n", result);
fflush(stdout);
bmp388.settings.op_mode = BMP3_MODE_NORMAL;
bmp3_set_op_mode(&bmp388);
printf("power mode set result is: %d\n", result);
while(1) {
bmp388.delay_us(1000000, bmp388.intf_ptr);
bmp3_get_sensor_data(sensor_comp, &data, &bmp388);
printf("Sensor data temp: %lf press: %lf\n", data.temperature, data.pressure/100.0);
printf("Analyzed sensor data: %d\n", analyze_sensor_data(&data));
fflush(stdout);
printf("\n");
bmp388.delay_us(40000, bmp388.intf_ptr);
}
}
BMP3_INTF_RET_TYPE bmpWrite(uint8_t reg_addr, const uint8_t *read_data, uint32_t len, void *intf_ptr) {
// Signal the reg addr to be written to
i2c_write_blocking(i2c0, addr, ®_addr, sizeof(uint8_t), true);
// Write to reg
int8_t write_res = i2c_write_blocking(i2c0, addr, read_data, len, true);
return write_res > 0 ? BMP3_INTF_RET_SUCCESS : BMP3_E_COMM_FAIL;
}
BMP3_INTF_RET_TYPE bmpRead(uint8_t reg_addr, uint8_t *read_data, uint32_t len, void *intf_ptr) {
// To read, first write the register address wanting to be read
i2c_write_blocking(i2c0, addr, ®_addr, sizeof(uint8_t), true);
int8_t write_result = i2c_read_blocking(i2c0, addr, read_data, len, true);
return write_result > 0 ? BMP3_INTF_RET_SUCCESS : BMP3_E_COMM_FAIL;
}
BMP3_INTF_RET_TYPE bmpDelay(uint32_t amt, void *intf_ptr) {
sleep_us(amt);
return BMP3_INTF_RET_SUCCESS;
}
... View more