DS3232M RTC demo program. Tested on the K64F (this example) and the KL25Z, but should work on any platform by changing the SDA and SCL pins. USB serial baud rate is 230400, tested on TeraTerm. Demo includes setting the DS3232's time, turning on and off the 32KHz and 1Hz outputs and accessing the DS3232's temperature. Also included are DS3232 user RAM access tests and user RAM CRC data calculations. Since user RAM is battery backed up, CRC routines are included to insure that the data stored in user RAM is intact.

Dependencies:   ds3232m mbed mbed-rtos

Revision:
2:958004aa28a4
Parent:
1:c891c3930f4e
Child:
3:f0eb506d4add
--- a/main.cpp	Fri Dec 19 20:28:39 2014 +0000
+++ b/main.cpp	Tue Dec 23 20:11:26 2014 +0000
@@ -267,9 +267,11 @@
                 allowDisplayTime = false;
                 pcRxBuffer[0] = 'c';
             }
+            uint16_t errorValue = 0;
             if(pcRxBuffer[0] == 'g') {  //get and display stored data string
-                if(rtc.getUserRAM(pcRxBuffer, 128, 126) != 0) {
-                    pc.printf("Get user RAM error!!\r\n");
+                errorValue = rtc.getUserRAM(pcRxBuffer, 128, 126);
+                if(errorValue) {
+                    pc.printf("'Get' user RAM error: %d\r\n", errorValue);
                 } else if(pcRxBuffer[0] == NULL) {
                     pc.printf("User RAM empty!!\r\n");
                 } else {
@@ -277,6 +279,7 @@
                     pc.printf("%s\r\n", pcRxBuffer);
                 }
                 pcRxBuffer[0] = 'g';
+                errorValue = 0;
             }
             if(pcRxBuffer[0] == 's') {  //save data string
                 allowDisplayTime = true;
@@ -289,11 +292,11 @@
                     wait_ms(20);
 #endif
                 } while((pcRxLine == false) && (pcRxEOB == false));
-                if(rtc.putUserRAM(pcRxBuffer, 128, pcRxQty + 2) != 0) {
-                    pc.printf("Put user RAM error!!\r\n");
-                }
+                errorValue = rtc.putUserRAM(pcRxBuffer, 128, pcRxQty + 2);
+                if(errorValue) pc.printf("'Put' user RAM error: %d\r\n", errorValue);
                 allowDisplayTime = false;
                 pcRxBuffer[0] = 's';
+                errorValue = 0;
             }
             if(pcRxBuffer[0] == 't') Get3232Temp();  //display the DS3232's temperature
             if(pcRxBuffer[0] == 'z') {  
@@ -317,7 +320,7 @@
     pc.baud(230400);
     ctTime = time(NULL);
     StartTime = ctTime;                     //get time we started up
-    pc.printf("\r\n\r\nDS3232M demo  19-DEC-2014  K. Braun\r\n");
+    pc.printf("\r\n\r\nDS3232M demo  23-DEC-2014  K. Braun\r\n");
     
     //check for RTOS operation
 #ifdef RTOS_H
@@ -374,14 +377,14 @@
 #endif
     
     int CheckTime = ctTime;
-    pc.printf("Hit 'A' or 'a' key to turn on/off the 32KHz output\r\n");
-    pc.printf("Hit 'B' or 'b' key to turn on/off the 1Hz output (1Hz pin needs pull-up)\r\n");
-    pc.printf("Hit 'c' key to change the time in the DS3232's\r\n");
-    pc.printf("Hit 'g' key to get the data string from DS3232 user RAM\r\n");
-    pc.printf("Hit 's' key to store a data string in the DS3232 user RAM\r\n");
-    pc.printf("Hit 't' key to get the DS3232's temperature\r\n");
-    pc.printf("Hit 'z' key to get the user RAM CRC data\r\n");
-    pc.printf("Hit '^C' key to reboot\r\n");
+    pc.printf("Hit 'A' or 'a' - turn on/off the 32KHz output\r\n");
+    pc.printf("Hit 'B' or 'b' - turn on/off the 1Hz output (1Hz pin needs pull-up)\r\n");
+    pc.printf("Hit 'c' - change the date & time\r\n");
+    pc.printf("Hit 'g' - get data string from DS3232 user RAM\r\n");
+    pc.printf("Hit 's' - store data string in the DS3232 user RAM\r\n");
+    pc.printf("Hit 't' - get DS3232's temperature\r\n");
+    pc.printf("Hit 'z' - get user RAM CRC data\r\n");
+    pc.printf("Hit '^C' - reboot\r\n");
     pc.printf("\r\n");
     
     //Ready!!