Johnny Yam
/
DS1306_RTC
DS1306 RTC testing. set time to 4:44:30PM and set alarm for 4:44:44PM
Revision 0:883734dc25da, committed 2012-06-01
- Comitter:
- jyam
- Date:
- Fri Jun 01 00:00:14 2012 +0000
- Commit message:
- initial release
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 883734dc25da main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jun 01 00:00:14 2012 +0000 @@ -0,0 +1,144 @@ +#include "mbed.h" + +DigitalOut ce(p14); +SPI spi(p11, p12, p13); +Serial pc(USBTX, USBRX); // tx, rx +InterruptIn ir(p15); +//DigitalIn alm(p15); +DigitalOut myled(LED1); + + +void detect() { + pc.printf("Interrupt received\n"); + myled = 0; + // exit(0); +} + +int main() { + myled = 1; + ir.fall(&detect); + unsigned char response; + ce=0; + pc.printf("Start\n"); + spi.format(8,3); // DS1306 RTC supports mode 3 and 1 + spi.frequency(1000000); + + // set control register to enable write and enable alarm interrupts + ce = 1; + spi.write(0x8f); + spi.write(0x07); + ce = 0; + wait(1); + + // set time to 4:44:30PM + + // set seconds to 30 + ce = 1; + spi.write(0x80); + spi.write(0x30); + ce = 0; + wait(1); + + // set minutes to 44 + ce = 1; + spi.write(0x81); + spi.write(0x44); + ce = 0; + wait(1); + + // set to 12-hr mode, PM, and hour to 4 + ce = 1; + spi.write(0x82); + spi.write(0x64); + ce = 0; + wait(1); + + // read seconds + ce = 1; + spi.write(0x00); + response = spi.write(0x00); + ce = 0; + wait(1); + printf("seconds: %x\n", response); + + // read minutes + ce = 1; + spi.write(0x01); + response = spi.write(0x01); + ce = 0; + wait(1); + printf("minute: %x\n", response); + + // read what u wrote at that location (0x64: 12-hr mode, PM, and hour to 4) + ce = 1; + spi.write(0x02); + response = spi.write(0x02); + ce = 0; + wait(1); + printf("%x\n", response); + + // read seconds again (see if time incremented) + ce = 1; + spi.write(0x00); + response = spi.write(0x00); + ce = 0; + wait(1); + printf("seconds: %x\n", response); + + // set alarm to 4:44:44PM + + // set seconds to 44 + ce = 1; + spi.write(0x87); + spi.write(0x44); + ce = 0; + wait(1); + + // set minutes to 44 + ce = 1; + spi.write(0x88); + spi.write(0x44); + ce = 0; + wait(1); + + // set to 12-hr mode, PM, and hour to 4 + ce = 1; + spi.write(0x89); + spi.write(0x64); + ce = 0; + wait(1); + + // set alarm to not match day + ce = 1; + spi.write(0x8a); + spi.write(0x80); + ce = 0; + wait(1); + + // read time seconds + ce = 1; + spi.write(0x00); + response = spi.write(0x00); + ce = 0; + wait(1); + printf("seconds: %x\n", response); + + // enable alarm + ce = 1; + spi.write(0x8f); + spi.write(0x07); + ce = 0; + wait(1); + + while (true) { + // read time seconds + ce = 1; + spi.write(0x00); + response = spi.write(0x00); + ce = 0; + printf("seconds: %x\n", response); + wait(1); + } + + return 0; +}
diff -r 000000000000 -r 883734dc25da mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Jun 01 00:00:14 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479