sdcard

Dependencies:   SDFileSystem mbed

Fork of rtcfinalcodeyuppie by Pradeep Kotipalli

Committer:
pradeepvk2208
Date:
Mon Dec 22 14:33:30 2014 +0000
Revision:
4:374c51671a69
Parent:
3:6cde88f8c50f
Child:
5:3979ca24777a
final rtcsd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pradeepvk2208 3:6cde88f8c50f 1 #include "rtsc.h"
pradeepvk2208 3:6cde88f8c50f 2 SPI spi(PTD6, PTD7, PTD5);
pradeepvk2208 3:6cde88f8c50f 3 DigitalOut cs(PTD2);
pradeepvk2208 3:6cde88f8c50f 4
pradeepvk2208 4:374c51671a69 5 SDFileSystem sd(PTD6, PTD7, PTD5, D10,"sd");
pradeepvk2208 4:374c51671a69 6
pradeepvk2208 3:6cde88f8c50f 7 void spiwrite(int a)
pradeepvk2208 3:6cde88f8c50f 8 {
pradeepvk2208 3:6cde88f8c50f 9 cs=1;
pradeepvk2208 3:6cde88f8c50f 10 cs=0;
pradeepvk2208 3:6cde88f8c50f 11 spi.write(a);
pradeepvk2208 3:6cde88f8c50f 12 spi.write(0x01);
pradeepvk2208 3:6cde88f8c50f 13 }
pradeepvk2208 3:6cde88f8c50f 14
pradeepvk2208 3:6cde88f8c50f 15 int spiread(int a)
pradeepvk2208 3:6cde88f8c50f 16 {
pradeepvk2208 3:6cde88f8c50f 17 cs=1;
pradeepvk2208 3:6cde88f8c50f 18 cs=0;
pradeepvk2208 3:6cde88f8c50f 19 spi.write(a);
pradeepvk2208 3:6cde88f8c50f 20 return(spi.write(0x00));
pradeepvk2208 3:6cde88f8c50f 21 }
pradeepvk2208 3:6cde88f8c50f 22 char* getname(int year1,int month1,int date1,int day1,int hours1,int minutes1,int seconds1)
pradeepvk2208 3:6cde88f8c50f 23 {
pradeepvk2208 3:6cde88f8c50f 24 year1= hexint(year1);
pradeepvk2208 3:6cde88f8c50f 25 month1=hexint(month1);
pradeepvk2208 3:6cde88f8c50f 26 date1=hexint(date1);
pradeepvk2208 3:6cde88f8c50f 27 day1=hexint(day1);
pradeepvk2208 3:6cde88f8c50f 28 hours1=hexint(hours1);
pradeepvk2208 3:6cde88f8c50f 29 minutes1=hexint(minutes1);
pradeepvk2208 3:6cde88f8c50f 30 seconds1=hexint(seconds1);
pradeepvk2208 3:6cde88f8c50f 31 /*char y[3]=getstr(year);
pradeepvk2208 3:6cde88f8c50f 32 char m[3]=getstr(month);
pradeepvk2208 3:6cde88f8c50f 33 char dat[3]=getstr(date);
pradeepvk2208 3:6cde88f8c50f 34 char da[3]=getstr(day);
pradeepvk2208 3:6cde88f8c50f 35 char h[3]=getstr(hours);
pradeepvk2208 3:6cde88f8c50f 36 char mi[3]=getstr(minutes);
pradeepvk2208 3:6cde88f8c50f 37 char s[3]=getstr(seconds);*/
pradeepvk2208 3:6cde88f8c50f 38 char time[15];
pradeepvk2208 4:374c51671a69 39 sprintf(time,"%02d%02d%02d%02d%02d%02d%02d",year1,month1,date1,day1,hours1,minutes1,seconds1);
pradeepvk2208 3:6cde88f8c50f 40 return(time);
pradeepvk2208 3:6cde88f8c50f 41
pradeepvk2208 3:6cde88f8c50f 42 }
pradeepvk2208 3:6cde88f8c50f 43
pradeepvk2208 3:6cde88f8c50f 44 int hexint(int a)
pradeepvk2208 3:6cde88f8c50f 45 {
pradeepvk2208 3:6cde88f8c50f 46 a=(a/16)*10+(a%16);
pradeepvk2208 3:6cde88f8c50f 47 return a;
pradeepvk2208 3:6cde88f8c50f 48 }
pradeepvk2208 3:6cde88f8c50f 49
pradeepvk2208 3:6cde88f8c50f 50 char* getts(void)
pradeepvk2208 3:6cde88f8c50f 51 {
pradeepvk2208 3:6cde88f8c50f 52 spi.format(8,3);
pradeepvk2208 3:6cde88f8c50f 53 spi.frequency(1000000);
pradeepvk2208 3:6cde88f8c50f 54 spiwrite(0x80);
pradeepvk2208 3:6cde88f8c50f 55 spiwrite(0x81);
pradeepvk2208 3:6cde88f8c50f 56 spiwrite(0x82);
pradeepvk2208 3:6cde88f8c50f 57 spiwrite(0x83);
pradeepvk2208 3:6cde88f8c50f 58 spiwrite(0x84);
pradeepvk2208 3:6cde88f8c50f 59 spiwrite(0x85);
pradeepvk2208 3:6cde88f8c50f 60 spiwrite(0x86);
pradeepvk2208 3:6cde88f8c50f 61 for(int i=0;i<1000000;i++){
pradeepvk2208 3:6cde88f8c50f 62 int seconds=spiread(0x00);
pradeepvk2208 3:6cde88f8c50f 63 int minutes =spiread(0x01);
pradeepvk2208 3:6cde88f8c50f 64 int hours =spiread(0x02);
pradeepvk2208 3:6cde88f8c50f 65 int day =spi.write(0x03);
pradeepvk2208 3:6cde88f8c50f 66 int date =spiread(0x04);
pradeepvk2208 3:6cde88f8c50f 67 int month =spiread(0x05);
pradeepvk2208 3:6cde88f8c50f 68 int year =spiread(0x06);
pradeepvk2208 3:6cde88f8c50f 69 cs = 1;
pradeepvk2208 3:6cde88f8c50f 70
pradeepvk2208 3:6cde88f8c50f 71 wait(1);
pradeepvk2208 3:6cde88f8c50f 72 printf("Seconds register = %2X : %2X : %2X : %2X : %2X : %2X : %2X \n\r",year,month,date,day, hours,minutes,seconds);
pradeepvk2208 3:6cde88f8c50f 73 printf("b4 returning tmpstmp is : %s\n",getname(year,month,date,day,hours,minutes,seconds));
pradeepvk2208 4:374c51671a69 74 printf("Hello World!\n");
pradeepvk2208 4:374c51671a69 75 SensorData Sensor;
pradeepvk2208 4:374c51671a69 76
pradeepvk2208 4:374c51671a69 77 printf("Writing dummy values\n");
pradeepvk2208 4:374c51671a69 78 strcpy( Sensor.Voltage, "49");
pradeepvk2208 4:374c51671a69 79 strcpy( Sensor.Current, "83");
pradeepvk2208 4:374c51671a69 80 strcpy( Sensor.Temperature, "53");
pradeepvk2208 4:374c51671a69 81 strcpy( Sensor.PanelTemperature, "43");
pradeepvk2208 4:374c51671a69 82 Sensor.Vcell_soc='9';
pradeepvk2208 4:374c51671a69 83 Sensor.alerts= '4';
pradeepvk2208 4:374c51671a69 84 Sensor.crate='7';
pradeepvk2208 4:374c51671a69 85 Sensor.BatteryTemperature='6';
pradeepvk2208 4:374c51671a69 86 Sensor.faultpoll='4';
pradeepvk2208 4:374c51671a69 87 Sensor.faultir='g';
pradeepvk2208 4:374c51671a69 88 Sensor.power_mode='k';
pradeepvk2208 4:374c51671a69 89 strcpy( Sensor.AngularSpeed, "49");
pradeepvk2208 4:374c51671a69 90 strcpy(Sensor.Bnewvalue,"76");
pradeepvk2208 4:374c51671a69 91 SensorData* Sensor1= &Sensor;
pradeepvk2208 4:374c51671a69 92 printf("Done writing dummy values\n");
pradeepvk2208 4:374c51671a69 93 mkdir("/sd/hk", 0777);
pradeepvk2208 4:374c51671a69 94 char date2[100]="/sd/hk/";
pradeepvk2208 4:374c51671a69 95 strcat(date2,getname(year,month,date,day,hours,minutes,seconds));
pradeepvk2208 4:374c51671a69 96 strcat(date2,".txt");
pradeepvk2208 4:374c51671a69 97 FILE *fp ;
pradeepvk2208 4:374c51671a69 98 fp= fopen(date2, "w");
pradeepvk2208 4:374c51671a69 99 if(fp == NULL) {
pradeepvk2208 4:374c51671a69 100 error("Could not open file for write\n");
pradeepvk2208 3:6cde88f8c50f 101 }
pradeepvk2208 4:374c51671a69 102 else
pradeepvk2208 4:374c51671a69 103 {
pradeepvk2208 4:374c51671a69 104 fwrite(Sensor1, sizeof(*Sensor1), 1, fp);
pradeepvk2208 4:374c51671a69 105 fclose(fp);
pradeepvk2208 4:374c51671a69 106 printf("Mission Accomplished\n");
pradeepvk2208 4:374c51671a69 107 printf("Goodbye World!\n");
pradeepvk2208 4:374c51671a69 108 }
pradeepvk2208 4:374c51671a69 109 }}