Manuel Caballero / DS3231

Files at this revision

API Documentation at this revision

Comitter:
mcm
Date:
Wed Dec 20 13:02:35 2017 +0000
Parent:
2:3710775b1864
Commit message:
The driver was completed and tested ( NUCLEO-L152RE ), it works as expected.

Changed in this revision

DS3231.h Show annotated file Show diff for this revision Revisions of this file
diff -r 3710775b1864 -r 0226d018fdcb DS3231.h
--- a/DS3231.h	Wed Dec 20 12:42:33 2017 +0000
+++ b/DS3231.h	Wed Dec 20 13:02:35 2017 +0000
@@ -22,8 +22,75 @@
 /**
     Example:
 
-[todo]
+#include "mbed.h"
+#include "DS3231.h"
+
+DS3231 myDS3231       ( I2C_SDA, I2C_SCL, DS3231::DS3231_ADDRESS, 400000 );
+Serial pc             ( USBTX, USBRX );
+
+Ticker     newReading;
+DigitalOut myled(LED1);
+
+DS3231::DS3231_status_t             aux;
+DS3231::DS3231_vector_data_t        myDS3231_data;
+DS3231::DS3231_vector_date_time_t   myDS3231_date_time;
+uint8_t                             myState = 0;
+
+
+void changeDATA ( void )
+{
+    myState = 1;
+}
+
+
+int main()
+{
+    pc.baud ( 115200 );
+
+    // Disable the 32kHz output pin
+    aux  =   myDS3231.DS3231_Status32kHzPin      ( DS3231::STATUS_ENABLE_32KHZ_OUTPUT_DISABLED );
 
+    // DATE: 20/12/17  Century = 1  Wednesday ( = 3 )
+    myDS3231_date_time.Date         =   20;
+    myDS3231_date_time.Month        =   12;
+    myDS3231_date_time.Year         =   17;
+    myDS3231_date_time.Century      =   DS3231::MONTH_CENTURY_MASK;
+    myDS3231_date_time.DayOfWeek    =   3;
+    aux  =   myDS3231.DS3231_SetDate ( myDS3231_date_time );
+
+
+    // TIME: 11:22:33  12h PM
+    myDS3231_date_time.Hours         =   11;
+    myDS3231_date_time.Minutes       =   22;
+    myDS3231_date_time.Seconds       =   33;
+    myDS3231_date_time.Mode_12_n24   =   DS3231::HOURS_12_ENABLED;
+    myDS3231_date_time.Mode_nAM_PM   =   DS3231::HOURS_PM_ENABLED;
+    aux  =   myDS3231.DS3231_SetTime ( myDS3231_date_time );
+
+    newReading.attach( &changeDATA, 1 );                                        // the address of the function to be attached ( changeDATA ) and the interval ( 1s )
+
+    // Let the callbacks take care of everything
+    while(1) {
+        sleep();
+
+        myled = 1;
+
+        if ( myState == 1 ) {
+            // Get the data
+            aux  =   myDS3231.DS3231_StartNewConvertTemperature ();
+            aux  =   myDS3231.DS3231_ReadTemperature            ( &myDS3231_data );
+            aux  =   myDS3231.DS3231_GetDate                    ( &myDS3231_date_time );
+            aux  =   myDS3231.DS3231_GetTime                    ( &myDS3231_date_time );
+
+            pc.printf( "Date: %d/%d/%d Time: %d:%d:%d\nTemperature: %0.2f\r\n", myDS3231_date_time.Date, myDS3231_date_time.Month, myDS3231_date_time.Year, myDS3231_date_time.Hours,
+                                                                                myDS3231_date_time.Minutes, myDS3231_date_time.Seconds, myDS3231_data.Temperature );
+
+            myState  =   0;                                                     // Reset the variable
+        }
+
+        myled = 0;
+    }
+}
 */
 
 
@@ -37,7 +104,7 @@
     * @brief   DEFAULT ADDRESSES
     */
     typedef enum {
-        DS3231_ADDRESS     =   ( 0x68 << 1 )                                                /*!<   DS3231 I2C Address                                   */
+        DS3231_ADDRESS     =   ( 0x68 << 1 )                                    /*!<   DS3231 I2C Address                                   */
     } DS3231_address_t;