![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
sdcard
Dependencies: SDFileSystem mbed
Fork of rtcfinalcodeyuppie by
rtsc.cpp@5:3979ca24777a, 2015-02-03 (annotated)
- Committer:
- pradeepvk2208
- Date:
- Tue Feb 03 17:10:21 2015 +0000
- Revision:
- 5:3979ca24777a
- Parent:
- 4:374c51671a69
- Child:
- 6:31a33cbe6cdb
hi
Who changed what in which revision?
User | Revision | Line number | New 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 time[15]; |
pradeepvk2208 | 4:374c51671a69 | 32 | sprintf(time,"%02d%02d%02d%02d%02d%02d%02d",year1,month1,date1,day1,hours1,minutes1,seconds1); |
pradeepvk2208 | 5:3979ca24777a | 33 | |
pradeepvk2208 | 3:6cde88f8c50f | 34 | return(time); |
pradeepvk2208 | 3:6cde88f8c50f | 35 | |
pradeepvk2208 | 3:6cde88f8c50f | 36 | } |
pradeepvk2208 | 3:6cde88f8c50f | 37 | |
pradeepvk2208 | 3:6cde88f8c50f | 38 | int hexint(int a) |
pradeepvk2208 | 3:6cde88f8c50f | 39 | { |
pradeepvk2208 | 3:6cde88f8c50f | 40 | a=(a/16)*10+(a%16); |
pradeepvk2208 | 3:6cde88f8c50f | 41 | return a; |
pradeepvk2208 | 3:6cde88f8c50f | 42 | } |
pradeepvk2208 | 5:3979ca24777a | 43 | //storedata stores the dummy structure in the file with timestamp as the filename in HK directory |
pradeepvk2208 | 5:3979ca24777a | 44 | void storedata(void) |
pradeepvk2208 | 3:6cde88f8c50f | 45 | { |
pradeepvk2208 | 3:6cde88f8c50f | 46 | spi.format(8,3); |
pradeepvk2208 | 3:6cde88f8c50f | 47 | spi.frequency(1000000); |
pradeepvk2208 | 5:3979ca24777a | 48 | spiwrite(0x80); //write seconds to 01 |
pradeepvk2208 | 5:3979ca24777a | 49 | spiwrite(0x81); //write minutes t0 01 |
pradeepvk2208 | 5:3979ca24777a | 50 | spiwrite(0x82); //write hours to 01 |
pradeepvk2208 | 5:3979ca24777a | 51 | spiwrite(0x83); //write day of week to 01 |
pradeepvk2208 | 5:3979ca24777a | 52 | spiwrite(0x84); //write day of month to 01 |
pradeepvk2208 | 5:3979ca24777a | 53 | spiwrite(0x85); //write month to 01 |
pradeepvk2208 | 5:3979ca24777a | 54 | spiwrite(0x86); //write year to 01 |
pradeepvk2208 | 3:6cde88f8c50f | 55 | for(int i=0;i<1000000;i++){ |
pradeepvk2208 | 5:3979ca24777a | 56 | int seconds=spiread(0x00); //read seconds |
pradeepvk2208 | 5:3979ca24777a | 57 | int minutes =spiread(0x01); //read minutes |
pradeepvk2208 | 5:3979ca24777a | 58 | int hours =spiread(0x02); //read hours |
pradeepvk2208 | 5:3979ca24777a | 59 | int day =spi.write(0x03); //read day of the week |
pradeepvk2208 | 5:3979ca24777a | 60 | int date =spiread(0x04); //read day of the month |
pradeepvk2208 | 5:3979ca24777a | 61 | int month =spiread(0x05); //read month |
pradeepvk2208 | 5:3979ca24777a | 62 | int year =spiread(0x06); //read year |
pradeepvk2208 | 3:6cde88f8c50f | 63 | cs = 1; |
pradeepvk2208 | 3:6cde88f8c50f | 64 | |
pradeepvk2208 | 5:3979ca24777a | 65 | //Assigning dummy values to the structure |
pradeepvk2208 | 5:3979ca24777a | 66 | |
pradeepvk2208 | 4:374c51671a69 | 67 | SensorData Sensor; |
pradeepvk2208 | 4:374c51671a69 | 68 | |
pradeepvk2208 | 4:374c51671a69 | 69 | printf("Writing dummy values\n"); |
pradeepvk2208 | 4:374c51671a69 | 70 | strcpy( Sensor.Voltage, "49"); |
pradeepvk2208 | 4:374c51671a69 | 71 | strcpy( Sensor.Current, "83"); |
pradeepvk2208 | 5:3979ca24777a | 72 | Sensor.Temperature ='5'; |
pradeepvk2208 | 5:3979ca24777a | 73 | strcpy( Sensor.PanelTemperature, "4"); |
pradeepvk2208 | 4:374c51671a69 | 74 | Sensor.Vcell_soc='9'; |
pradeepvk2208 | 4:374c51671a69 | 75 | Sensor.alerts= '4'; |
pradeepvk2208 | 4:374c51671a69 | 76 | Sensor.crate='7'; |
pradeepvk2208 | 4:374c51671a69 | 77 | Sensor.BatteryTemperature='6'; |
pradeepvk2208 | 4:374c51671a69 | 78 | Sensor.faultpoll='4'; |
pradeepvk2208 | 4:374c51671a69 | 79 | Sensor.faultir='g'; |
pradeepvk2208 | 4:374c51671a69 | 80 | Sensor.power_mode='k'; |
pradeepvk2208 | 5:3979ca24777a | 81 | strcpy( Sensor.AngularSpeed, "9"); |
pradeepvk2208 | 5:3979ca24777a | 82 | strcpy(Sensor.Bnewvalue,"6"); |
pradeepvk2208 | 4:374c51671a69 | 83 | printf("Done writing dummy values\n"); |
pradeepvk2208 | 4:374c51671a69 | 84 | mkdir("/sd/hk", 0777); |
pradeepvk2208 | 4:374c51671a69 | 85 | char date2[100]="/sd/hk/"; |
pradeepvk2208 | 4:374c51671a69 | 86 | strcat(date2,getname(year,month,date,day,hours,minutes,seconds)); |
pradeepvk2208 | 4:374c51671a69 | 87 | strcat(date2,".txt"); |
pradeepvk2208 | 4:374c51671a69 | 88 | FILE *fp ; |
pradeepvk2208 | 4:374c51671a69 | 89 | fp= fopen(date2, "w"); |
pradeepvk2208 | 4:374c51671a69 | 90 | if(fp == NULL) { |
pradeepvk2208 | 4:374c51671a69 | 91 | error("Could not open file for write\n"); |
pradeepvk2208 | 3:6cde88f8c50f | 92 | } |
pradeepvk2208 | 4:374c51671a69 | 93 | else |
pradeepvk2208 | 4:374c51671a69 | 94 | { |
pradeepvk2208 | 5:3979ca24777a | 95 | fprintf(fp, "%s -", Sensor.Voltage); |
pradeepvk2208 | 5:3979ca24777a | 96 | fprintf(fp,"%s -",Sensor.Current); |
pradeepvk2208 | 5:3979ca24777a | 97 | fprintf(fp,"%c -",Sensor.Temperature); |
pradeepvk2208 | 5:3979ca24777a | 98 | fprintf(fp,"%s -",Sensor.PanelTemperature); |
pradeepvk2208 | 5:3979ca24777a | 99 | fprintf(fp,"%c -",Sensor.Vcell_soc); //printing the contents of the strucure in a single line in the file |
pradeepvk2208 | 5:3979ca24777a | 100 | fprintf(fp,"%c -",Sensor.alerts); |
pradeepvk2208 | 5:3979ca24777a | 101 | fprintf(fp,"%c -",Sensor.crate); |
pradeepvk2208 | 5:3979ca24777a | 102 | fprintf(fp,"%c -",Sensor.BatteryTemperature); |
pradeepvk2208 | 5:3979ca24777a | 103 | fprintf(fp,"%c -",Sensor.faultpoll); |
pradeepvk2208 | 5:3979ca24777a | 104 | fprintf(fp,"%c -",Sensor.faultir); |
pradeepvk2208 | 5:3979ca24777a | 105 | fprintf(fp,"%c -",Sensor.power_mode); |
pradeepvk2208 | 5:3979ca24777a | 106 | fprintf(fp,"%s -",Sensor.AngularSpeed); |
pradeepvk2208 | 5:3979ca24777a | 107 | fprintf(fp,"%s",Sensor.Bnewvalue); |
pradeepvk2208 | 4:374c51671a69 | 108 | fclose(fp); |
pradeepvk2208 | 5:3979ca24777a | 109 | printf("%s",getname(year,month,date,day,hours,minutes,seconds)); |
pradeepvk2208 | 5:3979ca24777a | 110 | wait(10); |
pradeepvk2208 | 5:3979ca24777a | 111 | |
pradeepvk2208 | 5:3979ca24777a | 112 | |
pradeepvk2208 | 4:374c51671a69 | 113 | } |
pradeepvk2208 | 4:374c51671a69 | 114 | }} |