COSA
An Object-Oriented Platform for Arduino Programming
DS1302 Class Reference

#include <DS1302.hh>

Collaboration diagram for DS1302:
Collaboration graph

Public Member Functions

 DS1302 (Board::DigitalPin cs=Board::D4, Board::DigitalPin sda=Board::D3, Board::DigitalPin clk=Board::D2)
 
uint8_t read (uint8_t addr)
 
void write (uint8_t addr, uint8_t data)
 
void write_protect (bool flag)
 
void get_time (time_t &now)
 
void set_time (time_t &now)
 
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 uint8_t RTC_START = 0
 
static const size_t RAM_MAX = 31
 
static const uint8_t RAM_START = 32
 
static const uint8_t RAM_END = RAM_START + RAM_MAX
 

Protected Types

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

Protected Member Functions

uint8_t read ()
 
void write (uint8_t data)
 

Protected Attributes

OutputPin m_cs
 Chip select, asserted high. More...
 
IOPin m_sda
 Serial data, bidirectional. More...
 
OutputPin m_clk
 Clock for synchronized data. More...
 

Static Protected Attributes

static const uint8_t WP = 0x07
 

Detailed Description

Cosa Device Driver for DS1302, Trickle-Charge Timekeeping Chip.

Circuit

DS1302/RTC
+------------+
(VCC)---------------1-|VCC |
(GND)---------------2-|GND |
(D2)----------------3-|CLK |
(D3)----------------4-|DAT |
(D4)----------------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 48 of file DS1302.hh.

Member Enumeration Documentation

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 159 of file DS1302.hh.

Constructor & Destructor Documentation

DS1302::DS1302 ( Board::DigitalPin  cs = Board::D4,
Board::DigitalPin  sda = Board::D3,
Board::DigitalPin  clk = Board::D2 
)
inline

Construct device driver for DS1302 Real-Time Clock with the given pins.

Parameters
[in]cschip select pin (default D4).
[in]sdaserial data pin (default D3).
[in]clkclock pin (default D2).

Definition at line 69 of file DS1302.hh.

Member Function Documentation

void DS1302::get_time ( time_t now)

Read clock and calender from the device.

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

Definition at line 79 of file DS1302.cpp.

uint8_t DS1302::read ( uint8_t  addr)

Definition at line 55 of file DS1302.cpp.

uint8_t DS1302::read ( )
protected

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.
Note
atomic

Definition at line 24 of file DS1302.cpp.

uint8_t DS1302::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 119 of file DS1302.hh.

void DS1302::read_ram ( void *  buf,
size_t  size 
)

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 113 of file DS1302.cpp.

void DS1302::set_time ( time_t now)

Write clock and calender to the device.

Parameters
[in]nowtime to set.

Definition at line 96 of file DS1302.cpp.

void DS1302::write ( uint8_t  addr,
uint8_t  data 
)

Definition at line 69 of file DS1302.cpp.

void DS1302::write ( uint8_t  data)
protected

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

Parameters
[in]datato write to the device.
Note
atomic

Definition at line 41 of file DS1302.cpp.

void DS1302::write_protect ( bool  flag)
inline

Set write protect-bit according to flag.

Parameters
[in]flagwrite protect mode.

Definition at line 97 of file DS1302.hh.

void DS1302::write_ram ( uint8_t  addr,
uint8_t  data 
)
inline

Write given data to the static memory (31 bytes). Requires handling of write protect (write_protect).

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

Definition at line 131 of file DS1302.hh.

void DS1302::write_ram ( void *  buf,
size_t  size 
)

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 127 of file DS1302.cpp.

Member Data Documentation

OutputPin DS1302::m_clk
protected

Clock for synchronized data.

Definition at line 169 of file DS1302.hh.

OutputPin DS1302::m_cs
protected

Chip select, asserted high.

Definition at line 167 of file DS1302.hh.

IOPin DS1302::m_sda
protected

Serial data, bidirectional.

Definition at line 168 of file DS1302.hh.

const uint8_t DS1302::RAM_END = RAM_START + RAM_MAX
static

End address of static memory.

Definition at line 60 of file DS1302.hh.

const size_t DS1302::RAM_MAX = 31
static

Static memory size.

Definition at line 54 of file DS1302.hh.

const uint8_t DS1302::RAM_START = 32
static

Start address of static memory.

Definition at line 57 of file DS1302.hh.

const uint8_t DS1302::RTC_START = 0
static

Start address of clock/calender internal registers.

Definition at line 51 of file DS1302.hh.

const uint8_t DS1302::WP = 0x07
staticprotected

Write protect register.

Definition at line 156 of file DS1302.hh.


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