Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX30003 max32630fthr DS1307
Diff: main.cpp
- Revision:
- 12:10b49ad3c492
- Parent:
- 11:300afaf2696b
- Child:
- 13:0e7bbc06083f
--- a/main.cpp Fri Sep 25 16:42:40 2020 +0000
+++ b/main.cpp Tue Sep 29 19:00:06 2020 +0000
@@ -18,7 +18,7 @@
DigitalOut ledA(LED2);
void ecg_config(MAX30003 &ecgAFE);
//BufferedSerial pc(P3_1,P3_0); // Use USB debug probe for serial link static Unbuffered
-static BufferedSerial pc(TARGET_TX_PIN, TARGET_RX_PIN, 115200);
+static BufferedSerial pc(TARGET_TX_PIN, TARGET_RX_PIN, 9600);
//Serial uart_1(USBTX, USBRX); // Use USB debug probe for serial link static Unbuffered
//
@@ -36,6 +36,18 @@
ecgFIFOIntFlag = 1;
}
+time_t asUnixTime(int year, int mon, int mday, int hour, int min, int sec) {
+ struct tm t;
+ t.tm_year = year - 1900;
+ t.tm_mon = mon - 1; // convert to 0 based month
+ t.tm_mday = mday;
+ t.tm_hour = hour;
+ t.tm_min = min;
+ t.tm_sec = sec;
+ t.tm_isdst = -1; // Is Daylight saving time on? 1 = yes, 0 = no, -1 = unknown
+
+ return mktime(&t); // returns seconds elapsed since January 1, 1970 (begin of the Epoch)
+}
int main(void)
{
// Constants
@@ -64,7 +76,7 @@
MAX30003 ecgAFE(spiBus, P5_3); // New MAX30003 on spiBus, CS = P5_3
ecg_config(ecgAFE); // Config ECG
-
+
ecgAFE.writeRegister( MAX30003::SYNCH , 0);
@@ -79,7 +91,7 @@
int16_t sample = 300;
uint8_t final[10];
- uint32_t packet_1 = 1600674360;
+
uint16_t checksum_ = 0;
uint16_t mod_checksum = 0;
@@ -90,7 +102,7 @@
uint8_t data_len_1 = 0;
uint8_t data_len_2 = 0;
-
+ uint32_t packet_1 = 0;
uint8_t cksm_1 = 0;
uint8_t cksm_2 = 0;
uint8_t header_device_id[3] = {0,0,210};
@@ -102,33 +114,40 @@
pc.write("Welcome",8*sizeof(char));
printf("In the main loop");
bool flag_first = false;
-
+ int counter_reader = 0;
do
{
- if (pc.readable()) {
+ if (pc.readable())
+ {
scanf("%s",buf);
printf("The entered string is %s : \n ",buf);
- uint32_t packet_1 = atoi(buf);
- flag_first = true;
+
+ packet_1 = atoi(buf);
+ set_time(packet_1);
+
+ counter_reader++;
+ //flag_first = true;
}
- }while (flag_first==false);
-
+ }while (counter_reader<=3); // take the third timestamp
while(1)
{
- if (timer_fast.read() > .9)
+ if (timer_fast.read() >= 0.95)
{
//t.start();
//ledA = !ledA;
-
+
pc.write((uint8_t *)header_device_id, sizeof(header_device_id));
pc.write((uint8_t *)header_packet_type, sizeof(header_packet_type));
- packet_1 ++;
+ time_t seconds = time(NULL);
+ packet_1 = seconds;
+ //packet_1 ++;
+ //printf("Time as seconds since January 1, 1970 = %d\n", packet_1);
p_1 = packet_1 & 0xff;
p_2 = (packet_1 >> 8) & 0xff;
p_3 = (packet_1 >> 16) & 0xff;
@@ -231,6 +250,7 @@
CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias
CNFG_GEN_r.bits.imag = 2; // Current magnitude = 10nA
CNFG_GEN_r.bits.en_dcloff = 1; // Enable DC lead-off detection
+ //CNFG_GEN_r.bits.fmstr = 1; //125 sps FMSTR 1
ecgAFE.writeRegister( MAX30003::CNFG_GEN , CNFG_GEN_r.all);