00001
00006 #ifndef DS1338_H_
00007 #define DS1338_H_
00008
00009 #include <stdint.h>
00010
00014 typedef union ds1338DateTimeControl
00015 {
00016 struct
00017 {
00018 uint8_t Seconds:7;
00019 uint8_t ClockHalt:1;
00020
00021 uint8_t Minutes;
00022
00023 uint8_t Hour:6;
00024 uint8_t AMPMEnable:1;
00025 uint8_t :1;
00026
00027 uint8_t Day;
00028 uint8_t Date;
00029 uint8_t Month;
00030 uint8_t Year;
00031 struct
00032 {
00033 uint8_t RateSelect:2;
00034 uint8_t :2;
00035 uint8_t SquareWaveEnable:1;
00036 uint8_t OscillatorStopFlag:1;
00037 uint8_t :1;
00038 uint8_t OutPin:1;
00039 } ControlRegister;
00040 };
00041 uint8_t rawData[8];
00042 } ds1338TDC;
00043
00044 #define DEVICE 0xD0
00045 #define WRITE 0x00
00046 #define READ 0x01
00047
00048 #define TWI_BITRATE 25000
00049 void ds1338_setup(); //Setups TWI interface
00050
00054 typedef enum
00055 {
00056 NO_ERROR,
00057 LOCATION_OUTOFBOUNDS,
00058 RANGE_OUTOFBOUNDS,
00059 NO_DEVICE,
00060 DEVICE_BUSY,
00061 BUS_ERROR
00062 } ds1338_status;
00063
00064 ds1338_status ds1338_readTimeDateControl(ds1338TDC * data);
00065
00066 ds1338_status ds1338_writeTimeDateControl(ds1338TDC * data);
00067
00068 ds1338_status ds1338_writeBufferToNVRAM(uint8_t start,uint8_t lenght, uint8_t * data);
00069 ds1338_status ds1338_readBufferFromNVRAM(uint8_t start,uint8_t lenght, uint8_t * data);
00070 ds1338_status ds1338_writeByteToNVRAM(uint8_t location, uint8_t data);
00071 ds1338_status ds1338_readByteFromNVRAM(uint8_t location, uint8_t * data);
00072
00073
00074 #endif