sdcard

Dependencies:   SDFileSystem mbed

Fork of rtcfinalcodeyuppie by Pradeep Kotipalli

Revision:
2:d67cd8569921
Parent:
1:d360ad53f8fd
Child:
3:6cde88f8c50f
--- a/main.cpp	Mon Dec 22 07:04:43 2014 +0000
+++ b/main.cpp	Mon Dec 22 09:27:47 2014 +0000
@@ -3,6 +3,9 @@
 DigitalOut cs(PTD2);
 
 void spiwrite(int);
+int spiread(int);
+int hexint(int);
+char* getname(int,int,int,int,int,int,int);
 
 
 int main() 
@@ -20,8 +23,15 @@
     spi.write(0x80);  // set write register to seconds
     spi.write(0x00);  // send value of one*/
     spiwrite(0x80);
+    spiwrite(0x81);
+    spiwrite(0x82);
+    spiwrite(0x83);
+    spiwrite(0x84);
+    spiwrite(0x85);
+    spiwrite(0x86);
     
-    cs=1;
+    
+   /* cs=1;
     cs=0;
      spi.write(0x81);  //write reg to minutes
     spi.write(0x00);
@@ -57,57 +67,59 @@
     spi.write(0x86);  // set write register to seconds
     spi.write(0x01);  // send value of one
     
-    cs=1;
+    cs=1;*/
     // Receive the contents of the seconds register
    
    for(int i=0;i<1000000;i++){
     
         
-    cs=0;
+    /*cs=0;
     spi.write(0x00);               // set read register to seconds
-    int seconds = spi.write(0x00);   // read the value
+    int seconds = spi.write(0x00);   // read the value*/
+    int seconds=spiread(0x00);
     
-    cs=1;
+    /*cs=1;
     cs=0;
     
-    spi.write(0x01);
-    int minutes =spi.write(0x00);
+    spi.write(0x01);*/
+    int minutes =spiread(0x01);
     
     
-    cs=1;
+    /*cs=1;
     cs=0;
     
-    spi.write(0x02);
-    int hours =spi.write(0x01);
-    cs = 1;  //This cs=1 is to make the chipselect line high to "deselect" the slave in our case RTC
+    spi.write(0x02);*/
+    int hours =spiread(0x02);
+   /* cs = 1;  //This cs=1 is to make the chipselect line high to "deselect" the slave in our case RTC
     
     cs=0;
     
-    spi.write(0x03);
-    int day =spi.write(0x01);
-    cs = 1;
+    spi.write(0x03);*/
+    int day =spi.write(0x03);
+    /*cs = 1;
     
     cs=0;
     
-    spi.write(0x04);
-    int date =spi.write(0x01);
-    cs = 1;
+    spi.write(0x04);*/
+    int date =spiread(0x04);
+    /*cs = 1;
     
     cs=0;
     
-    spi.write(0x05);
-    int month =spi.write(0x01);
-    cs = 1;
+    spi.write(0x05);*/
+    int month =spiread(0x05);
+    /*cs = 1;
     
     cs=0;
     
-    spi.write(0x06);
-    int year =spi.write(0x01);
+    spi.write(0x06);*/
+    int year =spiread(0x06);
     cs = 1;
     
     wait(1);
     //This printf function is to check the timestamp function in the terminal output
     printf("Seconds register = %2X : %2X : %2X : %2X : %2X : %2X : %2X \n\r",year,month,date,day, hours,minutes,seconds);
+     printf("b4 returning tmpstmp is : %s\n",getname(year,month,date,day,hours,minutes,seconds));
     }
     
     return 0;
@@ -122,4 +134,38 @@
         cs=0;
         spi.write(a);
         spi.write(0x01);
-    }
\ No newline at end of file
+    }
+    int spiread(int a)
+    {
+        cs=1;
+        cs=0;
+        spi.write(a);
+        return(spi.write(0x00));
+    }
+    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,"%2d%2d%2d%2d%2d%2d%2d",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