C code and C++ library, driver software for Maxim Integrated DS1775, DS75 thermometer and thermostat temperature sensor. Code supports continuous or shut-down/standby, hysteresis, alarm limits, comparator or interrupt mode, fault filtering, and active low/high. Compact 5-pin SOT23 packaging
Dependents: DS1775_Digital_Thermostat_Temperature
Diff: ds1775_c.cpp
- Revision:
- 9:315236fb3c6a
- Parent:
- 8:b2d4c71268aa
- Child:
- 10:03645de9c017
diff -r b2d4c71268aa -r 315236fb3c6a ds1775_c.cpp --- a/ds1775_c.cpp Sun Apr 07 07:43:11 2019 +0000 +++ b/ds1775_c.cpp Sun Apr 07 08:59:48 2019 +0000 @@ -57,6 +57,31 @@ return DS1775_NO_ERROR; } +/******************************************************************************/ +int ds1775_read_cfg_reg(uint8_t *value, I2C &i2c_bus) +{ + int32_t ret; + char data[1] = {0}; + char reg = DS1775_REG_CONFIGURATION; + + /* write to the Register Select, true is for repeated start */ + ret = i2c_bus.write(ds1775_write_address, ®, 1, true); + if (ret == 0) { + ret = i2c_bus.read(ds1775_read_address, data, 1, false); + if (ret == 0) { + *value = data[0]; + printf("%s: cfg %x\r\n", __func__, *value); + return DS1775_NO_ERROR; + } else { + printf("%s: failed to read data: ret: %d\r\n", __func__, ret); + } + } else { + printf("%s: failed to write to Register Select: ret: %d\r\n", + __func__, ret); + } + return DS1775_ERROR; +} + /******************************************************************************/ int ds1775_read_reg(uint16_t *value, char reg, I2C &i2c_bus) @@ -66,7 +91,7 @@ ds1775_raw_data tmp; if (reg <= DS1775_REG_MAX) { - /* write to the Register Select */ + /* write to the Register Select, true is for repeated start */ ret = i2c_bus.write(ds1775_write_address, ®, 1, true); /* read the two bytes of data */ if (ret == 0) { @@ -131,11 +156,6 @@ cmd[2] = tmp.lsb; ret = i2c_bus.write(ds1775_write_address, cmd, 3, false); if (ret == 0) { - if (DS1775_REG_CONFIGURATION == reg) { - ds1775_extended_format = 0; - if (tmp.uwrd & DS1775_CFG_EXTENDED_FORMAT) - ds1775_extended_format = 1; - } return DS1775_NO_ERROR; } else { printf("%s: I2C write error %d\r\n",__func__, ret); @@ -147,8 +167,29 @@ } } +/******************************************************************************/ +int ds1775_write_reg_one_byte(uint8_t value, char reg, I2C &i2c_bus) +{ + int32_t ret; + char cmd[2]; -int ds1775_write_cfg(uint16_t cfg, I2C &i2c_bus) + if (reg == DS1775_REG_CONFIGURATION) { + cmd[0] = reg; + cmd[1] = value; + ret = i2c_bus.write(ds1775_write_address, cmd, 2, false); + if (ret == 0) { + return DS1775_NO_ERROR; + } else { + printf("%s: I2C write error %d\r\n",__func__, ret); + return DS1775_ERROR; + } + } else { + printf("%s: register value invalid %x\r\n",__func__, reg); + return DS1775_ERROR; + } +} + +int ds1775_write_cfg(uint8_t cfg, I2C &i2c_bus) { return ds1775_write_reg(cfg, DS1775_REG_CONFIGURATION, i2c_bus); }