|
|
/*
|
|
|
* rtc1308.h
|
|
|
*
|
|
|
* Created on: Nov 4, 2014
|
|
|
* Author: Alan Aguilar Sologuren
|
|
|
*/
|
|
|
|
|
|
#ifndef RTC1308_H_
|
|
|
#define RTC1308_H_
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
#include <pins_arduino.h>
|
|
|
#include <Wire.h>
|
|
|
#include <Time.h>
|
|
|
#include <te_structs.h>
|
|
|
|
|
|
extern void ISR_gnss_pps(void);
|
|
|
|
|
|
namespace te_rtc{
|
|
|
|
|
|
#define DS1308_CTRL_ID 0x68
|
|
|
#define DS1308_RAM_BASE 0x08 /*!< Direccion base de la memoria RAM */
|
|
|
#define DS1308_RAM_MAX 0x37 /*!< Direccion del final de la RAM */
|
|
|
#define DS1308_RAM_REGS (DS1308_RAM_MAX - DS1308_RAM_BASE + 1)
|
|
|
|
|
|
#define DS1308_SEC_ADD 0x00 /*!< Direccion de registro de configuracion de segundos */
|
|
|
#define DS1308_MIN_ADD 0x01 /*!< Direccion de registro de configuracion de minutos */
|
|
|
#define DS1308_HOU_ADD 0x02 /*!< Direccion de registro de configuracion de horas */
|
|
|
#define DS1308_DOW_ADD 0x03 /*!< Direccion de registro de configuracion de dia de la semana */
|
|
|
#define DS1308_DAT_ADD 0x04 /*!< Direccion de registro de configuracion de dia del mes */
|
|
|
#define DS1308_MON_ADD 0x05 /*!< Direccion de registro de configuracion de mes */
|
|
|
#define DS1308_YEA_ADD 0x06 /*!< Direccion de registro de configuracion de ahno */
|
|
|
#define DS1308_CTL_ADD 0x07 /*!< Direccion de registro de control */
|
|
|
|
|
|
|
|
|
#define OUT 7 /*!< Bit 7 en DS1308_CTL_ADD */
|
|
|
#define ECLK 6 /*!< Bit 6 en DS1308_CTL_ADD */
|
|
|
#define OSF 5 /*!< Bit 5 en DS1308_CTL_ADD */
|
|
|
#define SQWE 4 /*!< Bit 4 en DS1308_CTL_ADD */
|
|
|
#define LOS 3 /*!< Bit 3 en DS1308_CTL_ADD */
|
|
|
#define BBCLK 2 /*!< Bit 2 en DS1308_CTL_ADD */
|
|
|
#define RS1 1 /*!< Bit 1 en DS1308_CTL_ADD */
|
|
|
#define RS0 0 /*!< Bit 0 en DS1308_CTL_ADD */
|
|
|
|
|
|
//pin ports
|
|
|
#define CLKIN 38 /*!< internal PPS output PD7 AVR <> 38 ARDUINO MEGA */
|
|
|
#define PPS 0 /*|< GNSS receptor PPS signal interrupt int0, port 2 (Arduino i/o), pe4 (avr i/o) */
|
|
|
|
|
|
|
|
|
void initialization(void);
|
|
|
void configure(rtc_config_struct &rtc);
|
|
|
void set_time(tmElements_t &tm);
|
|
|
void activate_pps(void);
|
|
|
|
|
|
uint8_t read_ram(uint8_t regaddr, uint8_t *pbuf, uint8_t cnt);
|
|
|
uint8_t write_ram(uint8_t regaddr, uint8_t val);
|
|
|
uint8_t write_ram(uint8_t regaddr, const uint8_t *pbuf,uint8_t cnt);
|
|
|
|
|
|
inline uint8_t dec2bcd(uint8_t val);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif /* RTC1308_H_ */
|
|
|
|