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.
Fork of rtc_justtest by
main.cpp
00001 #include "mbed.h" 00002 00003 SPI spi(PTD6, PTD7, PTD5); // mosi, miso, sclk 00004 DigitalOut cs(D9); 00005 00006 00007 int main() 00008 { 00009 00010 00011 00012 // Setup the spi for 8 bit data, high steady state clock, 00013 // second edge capture, with a 1MHz clock rate 00014 spi.format(8,3); 00015 spi.frequency(3000000); 00016 00017 cs = 0; 00018 spi.write(0x80); // set write register to seconds 00019 spi.write(0x01); // send value of zero 00020 00021 cs=1; 00022 cs=0; 00023 spi.write(0x81); 00024 spi.write(0x58); //write reg to minutes 00025 00026 cs=1; 00027 cs=0; 00028 00029 spi.write(0x82); 00030 spi.write(0x01); //write reg to hours (00-23) 00031 00032 cs=1; 00033 cs=0; 00034 00035 spi.write(0x83); 00036 spi.write(0x01); //write reg to day (1-7) 00037 00038 cs=1; 00039 cs=0; 00040 00041 spi.write(0x84); 00042 spi.write(0x01); //write reg to date(01-31) 00043 00044 cs=1; 00045 cs=0; 00046 00047 spi.write(0x85); 00048 spi.write(0x01); //write reg to mnth(01-12) 00049 00050 cs=1; 00051 cs=0; 00052 00053 spi.write(0x86); 00054 spi.write(0x01); //write reg to year(00-99) 00055 00056 cs=1; 00057 // Receive the contents of the seconds register 00058 00059 for(int i=0;i<1000000;i++){ 00060 00061 00062 cs=0; 00063 spi.write(0x00); // set read register to seconds 00064 int seconds = spi.write(0x00); // read the value by sending dummy byte 00065 00066 cs=1; 00067 cs=0; 00068 00069 spi.write(0x01); 00070 int minutes =spi.write(0x01); 00071 00072 cs=1; 00073 cs=0; 00074 00075 spi.write(0x02); 00076 int hours =spi.write(0x01); 00077 00078 cs=1; 00079 cs=0; 00080 00081 spi.write(0x03); 00082 int day =spi.write(0x01); 00083 00084 cs=1; 00085 cs=0; 00086 00087 spi.write(0x04); 00088 int date =spi.write(0x01); 00089 00090 cs=1; 00091 cs=0; 00092 00093 spi.write(0x05); 00094 int mnth =spi.write(0x01); 00095 00096 cs=1; 00097 cs=0; 00098 00099 spi.write(0x06); 00100 int year =spi.write(0x01); 00101 00102 //This cs=1 is to make the chipselect line high to "deselect" the slave in our case RTC 00103 cs = 1; 00104 00105 //This printf function is to check the timestamp function in the terminal output 00106 printf("timestamp as = %X : %X : %X : %X : %X : %X : %X\n\r", year,mnth,date,day,hours,minutes,seconds); 00107 } 00108 00109 00110 00111 return 0; 00112 00113 }
Generated on Thu Oct 6 2022 06:17:54 by
1.7.2
