RTC_MUX_3Channel_Working

Dependencies:   MAX30003 max32630fthr DS1307

Revision:
17:f0008ebb1040
Parent:
16:520034b124b6
Child:
18:101042d225ef
--- a/main.cpp	Wed Jun 09 17:04:56 2021 +0000
+++ b/main.cpp	Wed Jun 09 17:24:31 2021 +0000
@@ -6,10 +6,14 @@
 //#include <BufferedSerial.h>
 #include <string>
 //#include <Serial.h>
+#include "ds3231.h"
 
 #define TARGET_TX_PIN P0_1
 #define TARGET_RX_PIN P0_0
 
+#define SDA P3_4
+#define SCL P3_5
+
 Timer timer_fast;
 Timer t;
 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
@@ -70,6 +74,35 @@
     const int FIFO_VALID_SAMPLE_MASK =  0x0;
     const int FIFO_FAST_SAMPLE_MASK =  0x1;
     const int ETAG_BITS_MASK = 0x7;
+    
+//-------------------------------------------------------------RTC-------------------------------------------------------------//     
+   //instantiate rtc object
+Ds3231 rtc(SDA, SCL); 
+
+ uint16_t rtn_val;
+ 
+ //time = 12:00:00 AM 12hr mode
+ ds3231_time_t time = {0,50,14,1, 0};  // seconds, min, hours, am_pm, mode
+
+ 
+rtn_val = rtc.set_time(time);
+ 
+  
+  //see datasheet for calendar format
+ ds3231_calendar_t calendar = {1, 8, 06, 21}; // day date month year
+
+
+ rtn_val = rtc.set_calendar(calendar);
+ 
+ 
+//see datasheet for calendar format
+
+ ds3231_cntl_stat_t data = {0x1C, 0x08}; 
+
+ rtn_val = rtc.set_cntl_stat_reg(data);
+ //------------------------------------------------------------------------------------------------------------------------------//
+    
+    
     timer_fast.start();
     DigitalOut rLed(LED2, LED_ON);
 //    pc.baud(9600);
@@ -132,40 +165,20 @@
    // printf("In the main loop"); //printf("In the main loop");
      bool flag_first = false;
        bool timestamp_reader = false;
-  /*   do
-    {
-       if (pc.readable()) 
-     {     
-     scanf("%s",buf);
-    printf("The entered string is %s : \n ",buf);*/
-   // buf[20] = 1621297647;
-     packet_1 =  1623243727; //atoi(buf);
-     set_time(packet_1);
+       
+       
+       time_t epoch_time;  
+       
+           do {
+    rtc.get_time(&time);
+    rtc.get_calendar(&calendar); 
+    epoch_time = rtc.get_epoch();
+    //printf("seconds since the Epoch: %ld\n", epoch_time);
      
-  /*   if ((packet_1 % 60) == 0)
-         { 
-             for (int u = 0;u<3;u++)
-             {
-                 if (pc.readable()) 
-                {     
-                    scanf("%s",buf);
-                    printf("Entered the minute string  %s : \n ",buf);
-                 
-                    packet_1 = atoi(buf);
-                    set_time(packet_1);
-                }
-             }
-       timestamp_reader = true;
-    }
-       else
-        {
-             //printf("The timestamp is not divisible by 60 \n");
-   /*  }
-     flag_first = true;
-    
-        }
-        
-     }   while (timestamp_reader==false); */ // take the third timestamp 
+    packet_1 = epoch_time;
+      }while((epoch_time % 60)!=0);   // come out at the start of minute
+  
+  
 while(1) 
     {
        
@@ -181,8 +194,9 @@
       pc.write((uint8_t *)header_device_id, sizeof(header_device_id));
       
       pc.write((uint8_t *)header_packet_type, sizeof(header_packet_type));
-       time_t seconds = time(NULL);          // if remove it the timestamp will be static 
-      packet_1 = seconds;                     //
+       epoch_time = rtc.get_epoch();
+       //time_t seconds = time(NULL);          // if remove it the timestamp will be static 
+      packet_1 = epoch_time;                     //
       //packet_1 ++;
      // printf("Time as seconds since January 1, 1970 = %d\n", packet_1);
       p_1 = packet_1 & 0xff;