
Simple test of DS1302 Real Time Clock module and an STM32 NUCLEO F441RE board.
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* 00002 -------------------- 00003 Author: L. Arrigoni 00004 May 2021 00005 -------------------- 00006 00007 Simple test with RTC module and STM32F411RE Nucleo board. 00008 DS1302 powered by 3.3 V without pull up resistor on I2C lines 00009 00010 */ 00011 00012 00013 #define SCLK D15 00014 #define IO D14 00015 #define CE D8 00016 00017 //Comment this line if the DS1302 is already running 00018 //#define INITIAL_RUN 00019 00020 #include "mbed.h" 00021 #include "DS1302.h" 00022 00023 DS1302 clk(SCLK, IO, CE); 00024 00025 int main() { 00026 #ifdef INITIAL_RUN 00027 //clk.set_time(1256729737); 00028 clk.set_time(1623257900); //from https://www.unixtimestamp.com/ 00029 #endif 00030 00031 char storedByte = clk.recallByte(0); 00032 printf("\r\nStored byte was %d, now increasing by one\r\n", storedByte); 00033 clk.storeByte(0, storedByte + 1); 00034 00035 while(1) { 00036 time_t seconds = clk.time(NULL); 00037 printf("Date and time: %s\r", ctime(&seconds)); 00038 wait(1); 00039 } 00040 } 00041 00042
Generated on Fri Jul 29 2022 15:31:18 by
