Arduino-RTC
Real-Time Clock (RTC) library for Arduino
DS1302< CS_PIN, SDA_PIN, CLK_PIN > Class Template Reference

#include <DS1302.h>

Collaboration diagram for DS1302< CS_PIN, SDA_PIN, CLK_PIN >:
Collaboration graph

Classes

struct  rtc_t
 

Public Member Functions

 DS1302 ()
 
void get_time (struct tm &now)
 
void set_time (struct tm &now)
 
void write_enable ()
 
void write_disable ()
 
uint8_t read_ram (uint8_t addr)
 
void write_ram (uint8_t addr, uint8_t data)
 
void read_ram (void *buf, size_t size)
 
void write_ram (void *buf, size_t size)
 

Static Public Attributes

static const size_t RAM_MAX = 31
 

Protected Types

enum  {
  WRITE = 0x80, READ = 0x81, RTC_BURST = 0xbe, RAM_BURST = 0xfe,
  ADDR_MASK = 0x3f
}
 

Protected Member Functions

uint8_t read (uint8_t addr)
 
void write (uint8_t addr, uint8_t data)
 
uint8_t read ()
 
void write (uint8_t data)
 

Protected Attributes

GPIO< CS_PIN > m_cs
 Chip select, asserted high. More...
 
GPIO< SDA_PIN > m_sda
 Serial data, bidirectional. More...
 
GPIO< CLK_PIN > m_clk
 Clock for synchronized data. More...
 

Static Protected Attributes

static const uint8_t RAM_START = 32
 
static const uint8_t WP = 0x07
 

Detailed Description

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
class DS1302< CS_PIN, SDA_PIN, CLK_PIN >

GPIO based device driver for DS1302, Trickle-Charge Timekeeping Chip.

Parameters
[in]CS_PINchip select board pin.
[in]SDA_PINserial data board pin.
[in]CLK_PINclock board pin.

Circuit

+------------+
(VCC)---------------1-|VCC |
(GND)---------------2-|GND |
(CLK)---------------3-|CLK |
(SDA)---------------4-|DAT |
(CS)----------------5-|RST |
+------------+

References

  1. On-line product description, http://www.maximintegrated.com/datasheet/index.mvp/id/2685
  2. Datasheet, http://datasheets.maximintegrated.com/en/ds/DS1302.pdf

Definition at line 53 of file DS1302.h.

Member Enumeration Documentation

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
anonymous enum
protected

Command byte.

Enumerator
WRITE 

Read/write bit in write mode.

READ 

Read/write bit in read mode.

RTC_BURST 

RTC register burst transfer.

RAM_BURST 

RAM burst transfer.

ADDR_MASK 

Mask address bits.

Definition at line 214 of file DS1302.h.

Constructor & Destructor Documentation

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
DS1302< CS_PIN, SDA_PIN, CLK_PIN >::DS1302 ( )
inline

Construct device driver for DS1302 Real-Time Clock with the given pins. Initiate pins (output mode).

Definition at line 62 of file DS1302.h.

Member Function Documentation

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
void DS1302< CS_PIN, SDA_PIN, CLK_PIN >::get_time ( struct tm now)
inline

Read clock and calender from the device. Return in standard time structure.

Parameters
[in,out]nowtime structure for return value.

Definition at line 76 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
uint8_t DS1302< CS_PIN, SDA_PIN, CLK_PIN >::read ( uint8_t  addr)
inlineprotected

Low level RTC access function. Read data from the clock/calender register or static memory on device.

Parameters
[in]addrdevice address.
Returns
data.

Definition at line 246 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
uint8_t DS1302< CS_PIN, SDA_PIN, CLK_PIN >::read ( )
inlineprotected

Low level read data from the device. Internal transfer function. Used within a chip select block. Data direction must be set before calling this function.

Returns
data read from the device.

Definition at line 280 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
uint8_t DS1302< CS_PIN, SDA_PIN, CLK_PIN >::read_ram ( uint8_t  addr)
inline

Read given static memory address on the device and return byte.

Parameters
[in]addrmemory address on the device (0..RAM_MAX-1).

Definition at line 149 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
void DS1302< CS_PIN, SDA_PIN, CLK_PIN >::read_ram ( void *  buf,
size_t  size 
)
inline

Burst read memory block from the device starting at address zero(0). Data block is returned in the given buffer.

Parameters
[in]bufpointer to buffer to store data read.
[in]sizenumber of bytes to read (max RAM_MAX(31)).

Definition at line 173 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
void DS1302< CS_PIN, SDA_PIN, CLK_PIN >::set_time ( struct tm now)
inline

Write clock and calender in given standard time structure to the device.

Parameters
[in]nowtime to set.

Definition at line 104 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
void DS1302< CS_PIN, SDA_PIN, CLK_PIN >::write ( uint8_t  addr,
uint8_t  data 
)
inlineprotected

Low level RTC access function. Write given data to the clock register or static memory on device.

Parameters
[in]addrdevice address.
[in]datato write.

Definition at line 265 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
void DS1302< CS_PIN, SDA_PIN, CLK_PIN >::write ( uint8_t  data)
inlineprotected

Write low level data to the device. Internal transfer function. Used within a chip select block.

Parameters
[in]datato write to the device.

Definition at line 300 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
void DS1302< CS_PIN, SDA_PIN, CLK_PIN >::write_disable ( )
inline

Disable write of clock/calender or memory.

Definition at line 139 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
void DS1302< CS_PIN, SDA_PIN, CLK_PIN >::write_enable ( )
inline

Enable write of clock/calender or memory.

Definition at line 130 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
void DS1302< CS_PIN, SDA_PIN, CLK_PIN >::write_ram ( uint8_t  addr,
uint8_t  data 
)
inline

Write given data to the static memory (31 bytes). Requires handling of write enable/disable.

Parameters
[in]addrmemory address (0..RAM_MAX-1).
[in]datato write to the memory address.

Definition at line 161 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
void DS1302< CS_PIN, SDA_PIN, CLK_PIN >::write_ram ( void *  buf,
size_t  size 
)
inline

Burst write data in buffer with given size to the static memory in the device (max 31 bytes). Burst write is always from address zero(0) and includes handling of write protect.

Parameters
[in]bufpointer to memory block to write.
[in]sizenumber of bytes to write (max RAM_MAX(31)).

Definition at line 193 of file DS1302.h.

Member Data Documentation

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
GPIO<CLK_PIN> DS1302< CS_PIN, SDA_PIN, CLK_PIN >::m_clk
protected

Clock for synchronized data.

Definition at line 238 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
GPIO<CS_PIN> DS1302< CS_PIN, SDA_PIN, CLK_PIN >::m_cs
protected

Chip select, asserted high.

Definition at line 236 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
GPIO<SDA_PIN> DS1302< CS_PIN, SDA_PIN, CLK_PIN >::m_sda
protected

Serial data, bidirectional.

Definition at line 237 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
const size_t DS1302< CS_PIN, SDA_PIN, CLK_PIN >::RAM_MAX = 31
static

Static memory size.

Definition at line 56 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
const uint8_t DS1302< CS_PIN, SDA_PIN, CLK_PIN >::RAM_START = 32
staticprotected

Start address of static memory.

Definition at line 208 of file DS1302.h.

template<BOARD::pin_t CS_PIN, BOARD::pin_t SDA_PIN, BOARD::pin_t CLK_PIN>
const uint8_t DS1302< CS_PIN, SDA_PIN, CLK_PIN >::WP = 0x07
staticprotected

Write protect register.

Definition at line 211 of file DS1302.h.


The documentation for this class was generated from the following file: