rtc function

Dependencies:   Date RTC8563 mbed

Committer:
wolpra98
Date:
Thu Apr 16 10:27:29 2015 +0000
Revision:
0:8a695c71f11b
rtc function

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolpra98 0:8a695c71f11b 1 //
wolpra98 0:8a695c71f11b 2 // @ Project : RTC Date Time Clock
wolpra98 0:8a695c71f11b 3 // @ File Name : RTC8563.cpp
wolpra98 0:8a695c71f11b 4 // @ Date : 06.04.2015
wolpra98 0:8a695c71f11b 5 // @ Author : Franz Pucher
wolpra98 0:8a695c71f11b 6 // @ Copyright : pe@bulme.at
wolpra98 0:8a695c71f11b 7 //
wolpra98 0:8a695c71f11b 8
wolpra98 0:8a695c71f11b 9 #include "mbed.h"
wolpra98 0:8a695c71f11b 10 #include "const.h"
wolpra98 0:8a695c71f11b 11
wolpra98 0:8a695c71f11b 12 #include "RTC8563.h"
wolpra98 0:8a695c71f11b 13
wolpra98 0:8a695c71f11b 14 RTC8563::RTC8563() : i2c(p28, p27) // delete void and add call to base constructor
wolpra98 0:8a695c71f11b 15 {
wolpra98 0:8a695c71f11b 16 // Initialise I2C
wolpra98 0:8a695c71f11b 17 i2c.frequency(40000);
wolpra98 0:8a695c71f11b 18 char init1[2] = {0x6, 0x00};
wolpra98 0:8a695c71f11b 19 char init2[2] = {0x7, 0xff};
wolpra98 0:8a695c71f11b 20 i2c.write(0x40, init1, 2);
wolpra98 0:8a695c71f11b 21 i2c.write(0x40, init2, 2);
wolpra98 0:8a695c71f11b 22 }
wolpra98 0:8a695c71f11b 23
wolpra98 0:8a695c71f11b 24 RTC8563::RTC8563(PinName sda, PinName scl) : i2c(sda, scl)
wolpra98 0:8a695c71f11b 25 {
wolpra98 0:8a695c71f11b 26 // Initialise I2C
wolpra98 0:8a695c71f11b 27 i2c.frequency(40000);
wolpra98 0:8a695c71f11b 28 char init1[2] = {0x6, 0x00};
wolpra98 0:8a695c71f11b 29 char init2[2] = {0x7, 0xff};
wolpra98 0:8a695c71f11b 30 i2c.write(0x40, init1, 2);
wolpra98 0:8a695c71f11b 31 i2c.write(0x40, init2, 2);
wolpra98 0:8a695c71f11b 32 }
wolpra98 0:8a695c71f11b 33
wolpra98 0:8a695c71f11b 34 char RTC8563::rtc_read(char address)
wolpra98 0:8a695c71f11b 35 {
wolpra98 0:8a695c71f11b 36 char value;
wolpra98 0:8a695c71f11b 37 i2c.start();
wolpra98 0:8a695c71f11b 38 i2c.write(RTC8563_ADR);
wolpra98 0:8a695c71f11b 39 i2c.write(address);
wolpra98 0:8a695c71f11b 40 i2c.start();
wolpra98 0:8a695c71f11b 41 i2c.write(RTC8563_ADR | _READ);
wolpra98 0:8a695c71f11b 42 value = i2c.read(0);
wolpra98 0:8a695c71f11b 43 i2c.stop();
wolpra98 0:8a695c71f11b 44
wolpra98 0:8a695c71f11b 45 return value;
wolpra98 0:8a695c71f11b 46 }
wolpra98 0:8a695c71f11b 47
wolpra98 0:8a695c71f11b 48 void RTC8563::rtc_write(char address, char value)
wolpra98 0:8a695c71f11b 49 {
wolpra98 0:8a695c71f11b 50 i2c.start();
wolpra98 0:8a695c71f11b 51 i2c.write(RTC8563_ADR);
wolpra98 0:8a695c71f11b 52 i2c.write(address);
wolpra98 0:8a695c71f11b 53 i2c.write(value);
wolpra98 0:8a695c71f11b 54 i2c.stop();
wolpra98 0:8a695c71f11b 55 }
wolpra98 0:8a695c71f11b 56
wolpra98 0:8a695c71f11b 57 void RTC8563::rtc_init()
wolpra98 0:8a695c71f11b 58 {
wolpra98 0:8a695c71f11b 59 }
wolpra98 0:8a695c71f11b 60
wolpra98 0:8a695c71f11b 61 void RTC8563::rtc_alarm()
wolpra98 0:8a695c71f11b 62 {
wolpra98 0:8a695c71f11b 63 }