sdcard

Dependencies:   SDFileSystem mbed

Fork of rtcfinalcodeyuppie by Pradeep Kotipalli

Committer:
duke970
Date:
Mon Dec 22 06:10:52 2014 +0000
Revision:
0:d5e352a3ea98
Child:
1:d360ad53f8fd
DS3234 RTC hard code ;

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