saiteja dommeti
/
testing_rtc
with one warning !!
Fork of testing_rtc by
Revision 1:620887c20cee, committed 2014-12-20
- Comitter:
- z3on
- Date:
- Sat Dec 20 10:30:39 2014 +0000
- Parent:
- 0:cfecb0ebcc63
- Commit message:
- testing rtc with one error of pointer being returned of a local variable of a function
Changed in this revision
diff -r cfecb0ebcc63 -r 620887c20cee main.cpp --- a/main.cpp Fri Dec 19 05:01:09 2014 +0000 +++ b/main.cpp Sat Dec 20 10:30:39 2014 +0000 @@ -1,33 +1,50 @@ #include "mbed.h" -SPI spi(PTD6, PTD7, PTD5); // mosi, miso, sclk -DigitalOut cs(PTA13); +#include "rtc_tst.h" +//SPI spi(PTD6, PTD7, PTD5); // mosi, miso, sclk +//DigitalOut cs(D9); int main() { + while(1) + { + Getts(); + } - // Setup the spi for 8 bit data, high steady state clock, + + /* // Setup the spi for 8 bit data, high steady state clock, // second edge capture, with a 1MHz clock rate spi.format(8,3); spi.frequency(1000000); - // Send the commands to write to test the seconds register cs = 0; spi.write(0x80); // set write register to seconds - spi.write(0x00); // send value of one + spi.write(0x00); // send value of zero //cs=1; //cs=0; - spi.write(0x81); //write reg to minutes - spi.write(0x00); + spi.write(0x81); + spi.write(0x00); //write reg to minutes //cs=1; //cs=0; - spi.write(0x82); //write reg to minutes - spi.write(0x00); + spi.write(0x82); + spi.write(0x15); //write reg to hours (00-23) + + spi.write(0x83); + spi.write(0x07); //write reg to day (1-7) + + spi.write(0x84); + spi.write(0x20); //write reg to date(01-31) + + spi.write(0x85); + spi.write(0x12); //write reg to mnth(01-12) + + spi.write(0x86); + spi.write(0x12); //write reg to year(00-99) cs=1; // Receive the contents of the seconds register @@ -36,8 +53,8 @@ cs=0; - spi.write(0x00); // set read register to seconds - int seconds = spi.write(0x00); // read the value + spi.write(0x00); // set read register to seconds + int seconds = spi.write(0x00); // read the value by sending dummy byte //cs=1; //cs=0; @@ -51,14 +68,27 @@ spi.write(0x02); int hours =spi.write(0x01); + spi.write(0x03); + int day =spi.write(0x01); + + spi.write(0x04); + int date =spi.write(0x01); + + spi.write(0x05); + int mnth =spi.write(0x01); + + spi.write(0x06); + int year =spi.write(0x01); + //This cs=1 is to make the chipselect line high to "deselect" the slave in our case RTC cs = 1; //This printf function is to check the timestamp function in the terminal output - printf("Seconds register = %X : %X : %X \n\r", hours,minutes,seconds); + printf("timestamp as = %X : %X : %X : %X : %X : %X : %X\n\r", hours,minutes,seconds,day,date,mnth,year); } return 0; + */
diff -r cfecb0ebcc63 -r 620887c20cee rtc_tst.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rtc_tst.cpp Sat Dec 20 10:30:39 2014 +0000 @@ -0,0 +1,121 @@ +#include "rtc_tst.h" +#include "string.h" + +SPI spi(PTD6, PTD7, PTD5); // mosi, miso, sclk +DigitalOut cs(D9); + + +char* Getts() + { + + // Setup the spi for 8 bit data, high steady state clock, + // second edge capture, with a 1MHz clock rate + spi.format(8,3); + spi.frequency(1000000); + + cs = 0; + spi.write(0x80); // set write register to seconds + spi.write(0x00); // send value of zero + + //cs=1; + //cs=0; + spi.write(0x81); + spi.write(0x00); //write reg to minutes + + //cs=1; + //cs=0; + + spi.write(0x82); + spi.write(0x15); //write reg to hours (00-23) + + spi.write(0x83); + spi.write(0x07); //write reg to day (1-7) + + spi.write(0x84); + spi.write(0x20); //write reg to date(01-31) + + spi.write(0x85); + spi.write(0x12); //write reg to mnth(01-12) + + spi.write(0x86); + spi.write(0x12); //write reg to year(00-99) + + cs=1; + // Receive the contents of the seconds register + + + + + cs=0; + spi.write(0x00); // set read register to seconds + int seconds = spi.write(0x00); // read the value by sending dummy byte + + //cs=1; + //cs=0; + + spi.write(0x01); + int minutes =spi.write(0x01); + + //cs=1; + //cs=0; + + spi.write(0x02); + int hours =spi.write(0x01); + + spi.write(0x03); + int day =spi.write(0x01); + + spi.write(0x04); + int date =spi.write(0x01); + + spi.write(0x05); + int month =spi.write(0x01); + + spi.write(0x06); + int year =spi.write(0x01); + + //This cs=1 is to make the chipselect line high to "deselect" the slave in our case RTC + cs = 1; + + //This printf function is to check the timestamp function in the terminal output + printf("timestamp as = %X : %X : %X : %X : %X : %X : %X\n\r", hours,minutes,seconds,day,date,month,year); + + + printf("b4 returning tmpstmp is : %s\n",getname(year,month,date,day,hours,minutes,seconds)); + return(getname(year,month,date,day,hours,minutes,seconds)); + + + } + + + + + + + char* getname(int year1,int month1,int date1,int day1,int hours1,int minutes1,int seconds1) +{ + year1= hexint(year1); + month1=hexint(month1); + date1=hexint(date1); + day1=hexint(day1); + hours1=hexint(hours1); + minutes1=hexint(minutes1); + seconds1=hexint(seconds1); + /*char y[3]=getstr(year); + char m[3]=getstr(month); + char dat[3]=getstr(date); + char da[3]=getstr(day); + char h[3]=getstr(hours); + char mi[3]=getstr(minutes); + char s[3]=getstr(seconds);*/ + char time[15]; + sprintf(time,"%d%d%d%d%d%d%d",year1,month1,date1,day1,hours1,minutes1,seconds1); + return(time); + +} + +int hexint(int a) +{ + a=(a/16)*10+(a%16); + return a; +} \ No newline at end of file
diff -r cfecb0ebcc63 -r 620887c20cee rtc_tst.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rtc_tst.h Sat Dec 20 10:30:39 2014 +0000 @@ -0,0 +1,6 @@ +#include "mbed.h" +#include "string.h" + +char* getname(int,int,int,int,int,int,int); +int hexint(int); +char* Getts();