#define BME280_ADDR 0xEC // 111011xR /* registers */ #define BME280_RESET 0xE0 #define BME280_CTRL_HUM 0xF2 #define BME280_STATUS 0xF3 #define BME280_CTRL_MEAS 0xF4 #define BME280_CONFIG 0xF5 #define BME280_PRESS_MSB 0xF7 /* values */ #define BME280_CFG_OSRSH 0x01 #define BME280_CFG_OSRST 0x01 #define BME280_CFG_OSRSP 0x01 #define BME280_CFG_T_SB 0x04 /* every 500 ms */ #define BME280_CFG_FILT 0x00 #define BME280_MODE_NORMAL 0x03 #define BME280_MODE_SLEEP 0x00 #define BME280_MODE_FORCED 0x01 void BME280_init(void) { uint8_t tmp; /* reset */ write_reg(BME280_ADDR, BME280_RESET, 0xB6); HAL_Delay(2); tmp = read_reg(BME280_ADDR, BME280_STATUS); while ((tmp & 0x1) != 0) { /* wait until NVM reading is finished */ tmp = read_reg(BME280_ADDR, BME280_STATUS); } /* read cal data */ BME280_read_cal_data(); /* configure */ tmp = ((BME280_CFG_OSRST & 7) << 5) || ((BME280_CFG_OSRSP & 7) << 2) || (BME280_MODE_NORMAL & 3); write_reg(BME280_ADDR, BME280_CONFIG, (((BME280_CFG_T_SB & 7) << 5) || ((BME280_CFG_FILT & 7) << 2))); write_reg(BME280_ADDR, BME280_CTRL_MEAS,tmp); write_reg(BME280_ADDR, BME280_CTRL_HUM, (BME280_CFG_OSRSH & 7)); write_reg(BME280_ADDR, BME280_CTRL_MEAS,tmp); } (The code tag doesn't seem to work.)
... View more