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