![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
vr1.1
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of CDMS_RTOS_v1_1 by
Diff: RTC.cpp
- Revision:
- 0:d6e3d1e21484
- Child:
- 2:4c79b3dfef31
diff -r 000000000000 -r d6e3d1e21484 RTC.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RTC.cpp Mon Jun 15 12:16:59 2015 +0000 @@ -0,0 +1,135 @@ +#include "mbed.h" +#include "func_head.h" + +SPI rtc_spi(PTD6,PTD7,PTD5); // MOSI,MISO, CLOCK microcontroller(in order) +DigitalOut rtc_cs(PTA13); //Slave Select pin +//Serial pc(USBTX,USBRX); + +uint8_t* FUNC_CDMS_RD_RTC() +{ + rtc_cs=1; + rtc_spi.format(8,0); + rtc_spi.frequency(1000000); + //clearing the halt bit + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x8C); + rtc_spi.write(0x00); + + //clearing the OF bit + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x8F); + rtc_spi.write(0x00); + + //century bits + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x80|0x03); + rtc_spi.write(0x00); + + //Kick starting the oscillator + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x81); //register address with write flag + rtc_spi.write(0x80);//enabling stop bit in the seconds register + + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x81); + rtc_spi.write(0x00);//disabling the stop bit to restart the oscillator + + + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x80); + rtc_spi.write(0x01); // set milliseconds value to 00 + rtc_cs=1; + + rtc_cs=0; + rtc_spi.write(0x81); + rtc_spi.write(0x01); //set seconds value to 00 + rtc_cs=1; + + rtc_cs=0; + rtc_spi.write(0x82); + rtc_spi.write(0x01);//set minutes value to 00 + rtc_cs=1; + + rtc_cs=0; + rtc_spi.write(0x83); + rtc_spi.write(0x23); //set the hours to 01 + rtc_cs=1; + + rtc_cs=0; + rtc_spi.write(0x84); + rtc_spi.write(0x01); //set day of the week to 01 + rtc_cs=1; + + rtc_cs=0; + rtc_spi.write(0x85); + rtc_spi.write(0x31); //set date of the month to 01 + rtc_cs=1; + + rtc_cs=0; + rtc_spi.write(0x86); + rtc_spi.write(0x12); //set month to 01 + rtc_cs=1; + + rtc_cs=0; + rtc_spi.write(0x87); + rtc_spi.write(0x01); //set year to 00(2000) + rtc_cs=1; + + uint8_t response; + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x00); //reading milliseconds register + response = rtc_spi.write(0x00); // read the value by sending dummy byte + uint8_t milliseconds = (uint8_t(response&0xF0)>>4)*10+uint8_t(response&0x0F)*1; + + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x01); //reading seconds register + response =rtc_spi.write(0x01); + uint8_t seconds = ((response&0x70)>>4)*10+(response&0x0F)*1; + + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x02); //reading minutes register + response =rtc_spi.write(0x01); + uint8_t minutes = ((response&0xF0)>>4)*10+(response&0x0F)*1; + + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x03); //reading hours register + response=rtc_spi.write(0x01); + uint8_t hours = ((response&0x30)>>4)*10+(response&0x0F)*1; + + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x04); //reading day's register + uint8_t day =rtc_spi.write(0x01); + + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x05); //reading date register + response =rtc_spi.write(0x01); + uint8_t date = ((response&0x30)>>4)*10+(response&0x0F)*1; + + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x06); //reading month registe + response =rtc_spi.write(0x01); + uint8_t month = ((response&0x10)>>4)*10+(response&0x0F)*1; + + rtc_cs=1; + rtc_cs=0; + rtc_spi.write(0x07); //reading year's registe + response =rtc_spi.write(0x01); + uint8_t year = ((response&0xF0)>>4)*10+(response&0x0F)*1; + //sprintf(Time_stamp,"%02d%02d%02d%02d%02d%02d%02d%02d",year, month, date, day, hours, minutes, seconds, milliseconds ); + uint8_t Time_stamp[8] = {year, month, date, day, hours, minutes, seconds, milliseconds}; + printf("read\r\n"); + return(Time_stamp); +}