diff --git a/docs/ESP32_clock_adjust.xlsx b/docs/ESP32_clock_adjust.xlsx index 95f0f0c..fcd260c 100644 Binary files a/docs/ESP32_clock_adjust.xlsx and b/docs/ESP32_clock_adjust.xlsx differ diff --git a/lib/RTC/PCF85063_Driver.cpp b/lib/RTC/PCF85063_Driver.cpp index 36422c3..9d2b9d7 100644 --- a/lib/RTC/PCF85063_Driver.cpp +++ b/lib/RTC/PCF85063_Driver.cpp @@ -1,5 +1,6 @@ #include "PCF85063_Driver.h" #include +#include namespace drivers { @@ -18,7 +19,7 @@ namespace drivers success &= m_i2c.write(m_address, RTC_CTRL_2_ADDR, {def_conf2}); } // set clock correction pulses - const uint8_t correction = 0b10000011; // fast mode +3 correction pulses, because clock is beyond + const uint8_t correction = 0xE7; // fast mode -25 correction pulses, because clock is beyond success &= m_i2c.write(m_address, RTC_OFFSET_ADDR, {correction}); if (!success) LOG_ERROR("RTC Init Failure"); @@ -160,6 +161,22 @@ namespace drivers return false; } + const bool PCF85063::setOffset(const uint8_t ofst) + { + LOG_INFO("RTC set offset [", printHex(ofst).c_str(), "]"); + return m_i2c.write(m_address, RTC_OFFSET_ADDR, {ofst}); + } + + const uint8_t PCF85063::getOffset() + { + std::vector buf; + if (m_i2c.read(m_address, RTC_OFFSET_ADDR, 1, buf)) { + LOG_INFO("RTC get offset [", printHex(buf.front()).c_str(), "]"); + return buf.front(); + } + return {}; + } + const std::string PCF85063::getTimeStr() { datetime_t dt; diff --git a/lib/RTC/PCF85063_Driver.h b/lib/RTC/PCF85063_Driver.h index c166e05..d6dd88e 100644 --- a/lib/RTC/PCF85063_Driver.h +++ b/lib/RTC/PCF85063_Driver.h @@ -83,7 +83,7 @@ namespace drivers } datetime_t; public: - PCF85063(I2C &i2c, const uint8_t address, const uint8_t ctrl1 = RTC_CTRL_1_DEFAULT, const uint8_t ctrl2 = RTC_CTRL_2_DEFAULT); + PCF85063(I2C &i2c, const uint8_t address = PCF85063_ADDRESS, const uint8_t ctrl1 = RTC_CTRL_1_DEFAULT, const uint8_t ctrl2 = RTC_CTRL_2_DEFAULT); const bool reset(void); @@ -100,6 +100,9 @@ namespace drivers const bool readAlarm(datetime_t &time); const bool getAlarmFlag(uint8_t &flags); + const bool setOffset(const uint8_t ofst); + const uint8_t getOffset(); + const std::string getTimeStr(); static const std::string datetime2str(const datetime_t &datetime); diff --git a/src/main.cpp b/src/main.cpp index edb4d2e..7797318 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,7 +34,7 @@ void loop() // Declared here to keep devices local to the main loop otherwise the kernel crashes // auto i2c = drivers::I2C(); auto bus = drivers::MODBUS(9600, SERIAL_8N1); - auto rtc = drivers::PCF85063(i2c, PCF85063_ADDRESS); + auto rtc = drivers::PCF85063(i2c); auto eth = drivers::Ethernet(conf.m_ethHostname); auto tmp = drivers::R4DCB08(bus, conf.m_modbusTemperatureAddr); auto seneca = drivers::S50140(bus, conf.m_modbusSenecaAddr);