sdcard

Dependencies:   SDFileSystem mbed

Fork of rtcfinalcodeyuppie by Pradeep Kotipalli

Committer:
pradeepvk2208
Date:
Mon Dec 22 07:04:43 2014 +0000
Revision:
1:d360ad53f8fd
Parent:
0:d5e352a3ea98
Child:
2:d67cd8569921
hi;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
duke970 0:d5e352a3ea98 1 #include "mbed.h"
duke970 0:d5e352a3ea98 2 SPI spi(PTD6, PTD7, PTD5); // mosi, miso, sclk
duke970 0:d5e352a3ea98 3 DigitalOut cs(PTD2);
duke970 0:d5e352a3ea98 4
pradeepvk2208 1:d360ad53f8fd 5 void spiwrite(int);
pradeepvk2208 1:d360ad53f8fd 6
duke970 0:d5e352a3ea98 7
duke970 0:d5e352a3ea98 8 int main()
duke970 0:d5e352a3ea98 9 {
duke970 0:d5e352a3ea98 10
duke970 0:d5e352a3ea98 11
duke970 0:d5e352a3ea98 12
duke970 0:d5e352a3ea98 13 // Setup the spi for 8 bit data, high steady state clock,
duke970 0:d5e352a3ea98 14 // second edge capture, with a 1MHz clock rate
duke970 0:d5e352a3ea98 15 spi.format(8,3);
duke970 0:d5e352a3ea98 16 spi.frequency(1000000);
duke970 0:d5e352a3ea98 17
duke970 0:d5e352a3ea98 18 // Send the commands to write to test the seconds register
pradeepvk2208 1:d360ad53f8fd 19 /*cs = 0;
duke970 0:d5e352a3ea98 20 spi.write(0x80); // set write register to seconds
pradeepvk2208 1:d360ad53f8fd 21 spi.write(0x00); // send value of one*/
pradeepvk2208 1:d360ad53f8fd 22 spiwrite(0x80);
duke970 0:d5e352a3ea98 23
duke970 0:d5e352a3ea98 24 cs=1;
duke970 0:d5e352a3ea98 25 cs=0;
duke970 0:d5e352a3ea98 26 spi.write(0x81); //write reg to minutes
duke970 0:d5e352a3ea98 27 spi.write(0x00);
pradeepvk2208 1:d360ad53f8fd 28 spiwrite(0x81);
duke970 0:d5e352a3ea98 29
duke970 0:d5e352a3ea98 30 cs=1;
duke970 0:d5e352a3ea98 31 cs=0;
duke970 0:d5e352a3ea98 32
duke970 0:d5e352a3ea98 33 spi.write(0x82); //write reg to minutes
duke970 0:d5e352a3ea98 34 spi.write(0x01);
duke970 0:d5e352a3ea98 35
duke970 0:d5e352a3ea98 36 cs=1;
duke970 0:d5e352a3ea98 37
duke970 0:d5e352a3ea98 38 cs = 0;
duke970 0:d5e352a3ea98 39 spi.write(0x83); // set write register to seconds
duke970 0:d5e352a3ea98 40 spi.write(0x01); // send value of one
duke970 0:d5e352a3ea98 41
duke970 0:d5e352a3ea98 42 cs=1;
duke970 0:d5e352a3ea98 43
duke970 0:d5e352a3ea98 44 cs = 0;
duke970 0:d5e352a3ea98 45 spi.write(0x84); // set write register to seconds
duke970 0:d5e352a3ea98 46 spi.write(0x01); // send value of one
duke970 0:d5e352a3ea98 47
duke970 0:d5e352a3ea98 48 cs=1;
duke970 0:d5e352a3ea98 49
duke970 0:d5e352a3ea98 50 cs = 0;
duke970 0:d5e352a3ea98 51 spi.write(0x85); // set write register to seconds
duke970 0:d5e352a3ea98 52 spi.write(0x01); // send value of one
duke970 0:d5e352a3ea98 53
duke970 0:d5e352a3ea98 54 cs=1;
duke970 0:d5e352a3ea98 55
duke970 0:d5e352a3ea98 56 cs = 0;
duke970 0:d5e352a3ea98 57 spi.write(0x86); // set write register to seconds
duke970 0:d5e352a3ea98 58 spi.write(0x01); // send value of one
duke970 0:d5e352a3ea98 59
duke970 0:d5e352a3ea98 60 cs=1;
duke970 0:d5e352a3ea98 61 // Receive the contents of the seconds register
duke970 0:d5e352a3ea98 62
duke970 0:d5e352a3ea98 63 for(int i=0;i<1000000;i++){
duke970 0:d5e352a3ea98 64
duke970 0:d5e352a3ea98 65
duke970 0:d5e352a3ea98 66 cs=0;
duke970 0:d5e352a3ea98 67 spi.write(0x00); // set read register to seconds
duke970 0:d5e352a3ea98 68 int seconds = spi.write(0x00); // read the value
duke970 0:d5e352a3ea98 69
duke970 0:d5e352a3ea98 70 cs=1;
duke970 0:d5e352a3ea98 71 cs=0;
duke970 0:d5e352a3ea98 72
duke970 0:d5e352a3ea98 73 spi.write(0x01);
duke970 0:d5e352a3ea98 74 int minutes =spi.write(0x00);
duke970 0:d5e352a3ea98 75
duke970 0:d5e352a3ea98 76
duke970 0:d5e352a3ea98 77 cs=1;
duke970 0:d5e352a3ea98 78 cs=0;
duke970 0:d5e352a3ea98 79
duke970 0:d5e352a3ea98 80 spi.write(0x02);
duke970 0:d5e352a3ea98 81 int hours =spi.write(0x01);
duke970 0:d5e352a3ea98 82 cs = 1; //This cs=1 is to make the chipselect line high to "deselect" the slave in our case RTC
duke970 0:d5e352a3ea98 83
duke970 0:d5e352a3ea98 84 cs=0;
duke970 0:d5e352a3ea98 85
duke970 0:d5e352a3ea98 86 spi.write(0x03);
duke970 0:d5e352a3ea98 87 int day =spi.write(0x01);
duke970 0:d5e352a3ea98 88 cs = 1;
duke970 0:d5e352a3ea98 89
duke970 0:d5e352a3ea98 90 cs=0;
duke970 0:d5e352a3ea98 91
duke970 0:d5e352a3ea98 92 spi.write(0x04);
duke970 0:d5e352a3ea98 93 int date =spi.write(0x01);
duke970 0:d5e352a3ea98 94 cs = 1;
duke970 0:d5e352a3ea98 95
duke970 0:d5e352a3ea98 96 cs=0;
duke970 0:d5e352a3ea98 97
duke970 0:d5e352a3ea98 98 spi.write(0x05);
duke970 0:d5e352a3ea98 99 int month =spi.write(0x01);
duke970 0:d5e352a3ea98 100 cs = 1;
duke970 0:d5e352a3ea98 101
duke970 0:d5e352a3ea98 102 cs=0;
duke970 0:d5e352a3ea98 103
duke970 0:d5e352a3ea98 104 spi.write(0x06);
duke970 0:d5e352a3ea98 105 int year =spi.write(0x01);
duke970 0:d5e352a3ea98 106 cs = 1;
duke970 0:d5e352a3ea98 107
duke970 0:d5e352a3ea98 108 wait(1);
duke970 0:d5e352a3ea98 109 //This printf function is to check the timestamp function in the terminal output
duke970 0:d5e352a3ea98 110 printf("Seconds register = %2X : %2X : %2X : %2X : %2X : %2X : %2X \n\r",year,month,date,day, hours,minutes,seconds);
duke970 0:d5e352a3ea98 111 }
duke970 0:d5e352a3ea98 112
duke970 0:d5e352a3ea98 113 return 0;
duke970 0:d5e352a3ea98 114
duke970 0:d5e352a3ea98 115
duke970 0:d5e352a3ea98 116
pradeepvk2208 1:d360ad53f8fd 117 }
pradeepvk2208 1:d360ad53f8fd 118
pradeepvk2208 1:d360ad53f8fd 119 void spiwrite(int a)
pradeepvk2208 1:d360ad53f8fd 120 {
pradeepvk2208 1:d360ad53f8fd 121 cs=1;
pradeepvk2208 1:d360ad53f8fd 122 cs=0;
pradeepvk2208 1:d360ad53f8fd 123 spi.write(a);
pradeepvk2208 1:d360ad53f8fd 124 spi.write(0x01);
duke970 0:d5e352a3ea98 125 }