10static constexpr uint32_t TEMPERATURE_TIMEOUT_ID = 0;
11static constexpr uint32_t PRESSURE_TIMEOUT_ID = 1;
13static const uint8_t MS5611_ADDRESS = 0x77;
14static const uint8_t MS5611_CMD_ADC_READ = 0x00;
15static const uint8_t MS5611_CMD_RESET = 0x1E;
16static const uint8_t MS5611_CMD_CONV_D1 = 0x40;
17static const uint8_t MS5611_CMD_CONV_D2 = 0x50;
18static const uint8_t MS5611_CMD_READ_PROM = 0xA2;
21 if (!this->
write_bytes(MS5611_CMD_RESET,
nullptr, 0)) {
26 for (uint8_t offset = 0; offset < 6; offset++) {
27 if (!this->
read_byte_16(MS5611_CMD_READ_PROM + (offset * 2), &this->
prom_[offset])) {
34void MS5611Component::dump_config() {
35 ESP_LOGCONFIG(TAG,
"MS5611:");
37 LOG_UPDATE_INTERVAL(
this);
38 LOG_SENSOR(
" ",
"Temperature", this->temperature_sensor_);
39 LOG_SENSOR(
" ",
"Pressure", this->pressure_sensor_);
41void MS5611Component::update() {
43 if (!this->
write_bytes(MS5611_CMD_CONV_D2 + 0x08,
nullptr, 0)) {
52 if (!this->
read_bytes(MS5611_CMD_ADC_READ, bytes, 3)) {
59 if (!this->
write_bytes(MS5611_CMD_CONV_D1 + 0x08,
nullptr, 0)) {
68 if (!this->
read_bytes(MS5611_CMD_ADC_READ, bytes, 3)) {
83 const uint16_t c3 = uint16_t(this->
prom_[2]);
84 const uint16_t c4 = uint16_t(this->
prom_[3]);
85 const int32_t c5 = int32_t(this->
prom_[4]);
86 const uint16_t c6 = uint16_t(this->
prom_[5]);
88 const int32_t d2 = raw_temperature;
91 const int64_t dt = d2 - (c5 << 8);
92 int32_t temp = (2000 + ((dt * c6) >> 23));
94 int64_t off = (c2 << 16) + ((dt * c4) >> 7);
95 int64_t sens = (c1 << 15) + ((dt * c3) >> 8);
98 const int32_t t2 = (dt * dt) >> 31;
99 int32_t off2 = ((5 * (temp - 2000) * (temp - 2000)) >> 1);
100 int32_t sens2 = ((5 * (temp - 2000) * (temp - 2000)) >> 2);
102 off2 = (off2 + 7 * (temp + 1500) * (temp + 1500));
103 sens2 = sens2 + ((11 * (temp + 1500) * (temp + 1500)) >> 1);
113 const int32_t p = ((((d1 * sens) >> 21) - off) >> 15);
119 PUBLISH_STATE(this->temperature_sensor_,
temperature);
120 PUBLISH_STATE(this->pressure_sensor_,
pressure);
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.