Library for Real Time Clock module MCP97410 based on Library for DS1307
Fork of RTC-DS1307 by
Revision 13:10e564536e23, committed 2015-03-08
- Comitter:
- charly
- Date:
- Sun Mar 08 21:12:29 2015 +0000
- Parent:
- 12:88f82e47b6a1
- Commit message:
- added Methods for reading and manipulating (inc/dec) the Calibration-Register of RTC
Changed in this revision
| Rtc_Mcp97410.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Rtc_Mcp97410.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Rtc_Mcp97410.cpp Fri Jan 16 21:17:52 2015 +0000
+++ b/Rtc_Mcp97410.cpp Sun Mar 08 21:12:29 2015 +0000
@@ -232,6 +232,74 @@
}
}
+
+uint8_t Rtc_Mcp97410::readTrim()
+{
+ uint8_t trim;
+ if (readRTC(ADDR_CAL, (char *) &trim, 1)) {
+ INFO("OSCTRIM: %02X \n", trim);
+ return trim;
+ } else {
+ return 0;
+ }
+}
+
+bool Rtc_Mcp97410::incTrim()
+{
+ uint8_t trim;
+ uint8_t trim_val;
+ uint8_t trim_sign;
+
+ readRTC(ADDR_CAL, (char *) &trim, 1);
+ trim_val = 0x7F&trim;
+ trim_sign= trim >> 7;
+ if (trim_sign == 1) {
+ // positive: inc
+ if (trim_val < 0x7F) {
+ trim_val = trim_val++;
+ }
+ } else {
+ // negative: dec
+ if (trim_val != 0) {
+ trim_val = trim_val--;
+ } else {
+ // change sign
+ trim_sign = 1;
+ }
+ }
+ trim = trim_sign <<7 | trim_val;
+ INFO("incTrim: New TRIM: %02X\n", trim);
+ return writeRTC(ADDR_CAL, (char *) &trim, 1);
+}
+
+bool Rtc_Mcp97410::decTrim()
+{
+ uint8_t trim;
+ uint8_t trim_val;
+ uint8_t trim_sign;
+
+ readRTC(ADDR_CAL, (char *) &trim, 1);
+ trim_val = 0x7F&trim;
+ trim_sign= trim >> 7;
+ if (trim_sign == 0) {
+ // negative: inc
+ if (trim_val < 0x7F) {
+ trim_val = trim_val++;
+ }
+ } else {
+ // positive: dec
+ if (trim_val != 0) {
+ trim_val = trim_val--;
+ } else {
+ // change sign
+ trim_sign = 0;
+ }
+ }
+ trim = trim_sign <<7 | trim_val;
+ INFO("decTrim: New TRIM: %02X\n", trim);
+ return writeRTC(ADDR_CAL, (char *) &trim, 1);
+}
+
bool Rtc_Mcp97410::disableEEPROMWrite()
{
// protect all EEPROM from write operations
@@ -280,7 +348,7 @@
// write 0x55 and then 0xAA to the EEUNLOCK-register
char reg =0x00;
bool result = true;
-
+
reg = 0x55;
result &= writeRTC(ADDR_ULID,®,1);
reg = 0xAA;
--- a/Rtc_Mcp97410.h Fri Jan 16 21:17:52 2015 +0000
+++ b/Rtc_Mcp97410.h Sun Mar 08 21:12:29 2015 +0000
@@ -223,8 +223,29 @@
*/
bool disableEEPROMWrite();
-
+ /** read the OSCTRIM-Register (0x08)
+ *
+ * -127 .. +127
+ * bit 7 is Sign
+ * bit 0:6 Trim-Value
+ */
+ uint8_t readTrim();
+
+ /** Increment TRIM-Value
+ *
+ * Increment TRIM-Value by one
+ */
+ bool incTrim();
+
+ /** Derement TRIM-Value
+ *
+ * Decrement TRIM-Value by one
+ */
+ bool decTrim();
+
+
/** read from EEPROM
+ *
* address from 0x00 to 0x7F
* all 128 Bytes can be read in one chunk
*
@@ -237,6 +258,7 @@
bool readEEPROM(int address, char* buffer, int len);
/** write to EEPROM
+ *
* address from 0x00 to 0x7F
* only maximum 8 Bytes can be written in one chunk
*
