sd 32 update

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cdms_rtc.h Source File

cdms_rtc.h

00001 void FCTN_CDMS_INIT_RTC()
00002 {
00003     gCS_RTC=1;
00004     spi.format(8,0);
00005     spi.frequency(1000000);
00006     //clearing the halt bit 
00007     gCS_RTC=1;
00008     gCS_RTC=0;
00009     spi.write(0x8C);
00010     spi.write(0x00);
00011      
00012     //clearing the OF bit 
00013     gCS_RTC=1;
00014     gCS_RTC=0;
00015     spi.write(0x8F);
00016     spi.write(0x00);
00017      
00018     //century bits
00019     gCS_RTC=1;
00020     gCS_RTC=0;
00021     spi.write(0x80|0x03);
00022     spi.write(0x00);
00023  
00024     //Kick starting the oscillator 
00025     gCS_RTC=1;
00026     gCS_RTC=0;
00027     spi.write(0x81); //register address with write flag
00028     spi.write(0x80);//enabling stop bit in the seconds register
00029  
00030     gCS_RTC=1;
00031     gCS_RTC=0;
00032     spi.write(0x81);
00033     spi.write(0x00);//disabling the stop bit to restart the oscillator 
00034  
00035     
00036     gCS_RTC=1;
00037     gCS_RTC=0;
00038     spi.write(0x80); 
00039     spi.write(0x01); // set milliseconds value to 00
00040     gCS_RTC=1;
00041  
00042     gCS_RTC=0;
00043     spi.write(0x81); 
00044     spi.write(0x01); //set seconds value to 00
00045     gCS_RTC=1;
00046  
00047     gCS_RTC=0;
00048     spi.write(0x82); 
00049     spi.write(0x01);//set minutes value to 00
00050     gCS_RTC=1;
00051  
00052     gCS_RTC=0;
00053     spi.write(0x83); 
00054     spi.write(0x23); //set the hours to 01
00055     gCS_RTC=1;
00056     
00057     gCS_RTC=0;
00058     spi.write(0x84); 
00059     spi.write(0x01); //set day of the week to 01
00060     gCS_RTC=1;
00061     
00062     gCS_RTC=0;
00063     spi.write(0x85); 
00064     spi.write(0x31); //set date of the month to 01
00065     gCS_RTC=1;
00066     
00067     gCS_RTC=0;
00068     spi.write(0x86); 
00069     spi.write(0x12); //set month to 01
00070     gCS_RTC=1;
00071     
00072     gCS_RTC=0;
00073     spi.write(0x87); 
00074     spi.write(0x01); //set year to 00(2000)
00075     gCS_RTC=1;
00076     printf("\n\r rtc initalised \n");
00077 }
00078  
00079 uint64_t FCTN_CDMS_RD_RTC()
00080 {    
00081     uint8_t response;
00082     printf("\n\r Entered rtc\n");
00083     gCS_RTC=1;
00084     gCS_RTC=0;
00085     spi.write(0x00); //reading milliseconds register
00086     response = spi.write(0x00); // read the value by sending dummy byte
00087     uint8_t centiseconds =  (uint8_t(response&0xF0)>>4)*10+uint8_t(response&0x0F)*1;
00088     
00089     gCS_RTC=1;
00090     gCS_RTC=0;
00091     spi.write(0x01); //reading seconds register
00092     response =spi.write(0x01);
00093     uint8_t seconds =  ((response&0x70)>>4)*10+(response&0x0F)*1;
00094     
00095     gCS_RTC=1;
00096     gCS_RTC=0;
00097     spi.write(0x02); //reading minutes register
00098     response =spi.write(0x01);
00099     uint8_t minutes =  ((response&0xF0)>>4)*10+(response&0x0F)*1;
00100     
00101     gCS_RTC=1;
00102     gCS_RTC=0;
00103     spi.write(0x03); //reading hours register
00104     response=spi.write(0x01);
00105     uint8_t hours =  ((response&0x30)>>4)*10+(response&0x0F)*1;
00106     
00107     gCS_RTC=1;
00108     gCS_RTC=0;
00109     spi.write(0x04); //reading day's  register
00110     uint8_t day =spi.write(0x01);
00111     
00112     gCS_RTC=1;
00113     gCS_RTC=0;
00114     spi.write(0x05); //reading date register
00115     response =spi.write(0x01);
00116     uint8_t date =  ((response&0x30)>>4)*10+(response&0x0F)*1;
00117     
00118     gCS_RTC=1;
00119     gCS_RTC=0;
00120     spi.write(0x06); //reading month registe
00121     response =spi.write(0x01);
00122     uint8_t month =  ((response&0x10)>>4)*10+(response&0x0F)*1;
00123     
00124     gCS_RTC=1;
00125     gCS_RTC=0;
00126     spi.write(0x07); //reading year's registe
00127     response =spi.write(0x01);
00128     uint8_t year =  ((response&0xF0)>>4)*10+(response&0x0F)*1;
00129     gCS_RTC=1;
00130     //sprintf(Time_stamp,"%02d%02d%02d%02d%02d%02d%02d%02d",year, month, date, day, hours, minutes, seconds, milliseconds );
00131     uint8_t Time_stamp[8] = {year, month, date, day, hours, minutes, seconds, centiseconds};
00132     for(int i= 0; i<8;i++)
00133         printf("%d\t",Time_stamp[i]);
00134     printf("read\r\n");
00135     uint64_t time;
00136     time = 0;
00137     time = time|(((uint64_t)(centiseconds&0x7F)));
00138     time = time|(((uint64_t)(seconds&0x3F))<<7);
00139     time = time|(((uint64_t)(minutes&0x3F))<<13);
00140     time = time|(((uint64_t)(hours&0x1F))<<19);
00141     time = time|(((uint64_t)(day&0x1F))<<24);
00142     time = time|(((uint64_t)(month&0x07))<<29);
00143     time = time|(((uint64_t)(year&0x03))<<33);
00144     time = (time&0x00000007FFFFFFFF);
00145     //printf("\n\r%x%x", (int)(time >> 32), (int)(time));
00146     printf("\n\r0x%016llx\n\r", time);
00147    return time;
00148 }