A feature complete driver for the ISL1208 real time clock from Intersil.

Dependents:   ISL1208_HelloWorld

Embed: (wiki syntax)

« Back to documentation index

ISL1208 Class Reference

ISL1208 Class Reference

ISL1208 class. More...

#include <ISL1208.h>

Public Types

enum  OscillatorMode { OSCILLATOR_CRYSTAL, OSCILLATOR_EXTERNAL }
 

Represents the different oscillator modes for the ISL1208.

More...
enum  OutputFrequency {
  FOUT_DISABLED = 0, FOUT_32768_HZ, FOUT_4096_HZ, FOUT_1024_HZ,
  FOUT_64_HZ, FOUT_32_HZ, FOUT_16_HZ, FOUT_8_HZ,
  FOUT_4_HZ, FOUT_2_HZ, FOUT_1_HZ, FOUT_1_2_HZ,
  FOUT_1_4_HZ, FOUT_1_8_HZ, FOUT_1_16_HZ, FOUT_1_32_HZ
}
 

Represents the different output frequencies for the IRQ/fOUT pin on the ISL1208.

More...
enum  PowerMode { POWER_NORMAL, POWER_LPMODE }
 

Represents the power mode of the ISL1208.

More...
enum  AlarmMode { ALARM_DISABLED, ALARM_SINGLE, ALARM_INTERRUPT }
 

Represents the alarm mode of the ISL1208.

More...
enum  BatteryModeATR { BMATR_ZERO = 0, BMATR_MINUS_0_5, BMATR_PLUS_0_5, BMATR_PLUS_1_0 }
 

Represents the different battery mode ATR selections of the ISL1208.

More...
enum  DigitalTrim {
  DTR_ZERO = 0, DTR_PLUS_20, DTR_PLUS_40, DTR_PLUS_60,
  DTR_MINUS_20 = 5, DTR_MINUS_40, DTR_MINUS_60
}
 

Represents the different digital trim selections of the ISL1208.

More...

Public Member Functions

 ISL1208 (PinName sda, PinName scl, int hz=400000)
 Create a ISL1208 object connected to the specified I2C pins.
bool open ()
 Probe for the ISL1208 and configure auto reset if present.
time_t time ()
 Get the current time from the ISL1208.
void time (time_t t)
 Set the current time on the ISL1208 from a Unix timestamp.
bool powerFailed ()
 Determine whether the RTC has completely lost power (and hence the time and SRAM)
bool batteryFlag ()
 Determine whether the RTC has been on battery backup.
void clearBatteryFlag ()
 Clear the battery backup flag.
bool alarmFlag ()
 Determine whether the alarm has matched the RTC.
void clearAlarmFlag ()
 Clear the alarm flag.
ISL1208::OscillatorMode oscillatorMode ()
 Get the current oscillator mode of the ISL1208.
void oscillatorMode (OscillatorMode mode)
 Set the oscillator mode of the ISL1208.
ISL1208::OutputFrequency foutFrequency ()
 Get the current output frequency on the IRQ/fOUT pin.
void foutFrequency (OutputFrequency freq)
 Set the output frequency on the IRQ/fOUT pin.
bool outputOnBattery ()
 Determine whether or not the IRQ/fOUT pin will continue to output on battery power.
void outputOnBattery (bool output)
 Set whether or not the IRQ/fOUT pin should continue to output on battery power.
ISL1208::PowerMode powerMode ()
 Get the current power mode of the ISL1208.
void powerMode (PowerMode mode)
 Set the power mode of the ISL1208.
ISL1208::AlarmMode alarmMode ()
 Get the current alarm mode of the ISL1208.
void alarmMode (AlarmMode mode)
 Set the alarm mode of the ISL1208.
float analogTrim ()
 Get the current analog trim of the ISL1208.
void analogTrim (float trim)
 Set the analog trim of the ISL1208.
ISL1208::BatteryModeATR batteryModeATR ()
 Get the current battery mode analog trim of the ISL1208.
void batteryModeATR (BatteryModeATR atr)
 Set the battery mode analog trim of the ISL1208.
ISL1208::DigitalTrim digitalTrim ()
 Get the current digital trim of the ISL1208.
void digitalTrim (DigitalTrim dtr)
 Set the digital trim of the ISL1208.
time_t alarmTime ()
 Get the alarm time from the ISL1208.
void alarmTime (time_t t, bool sc=true, bool mn=true, bool hr=true, bool dt=true, bool mo=true, bool dw=true)
 Set the alarm time on the ISL1208 from a Unix timestamp.
unsigned short sram ()
 Read the contents of the battery-backed SRAM.
void sram (unsigned short data)
 Write new data to the battery-backed SRAM.

Detailed Description

ISL1208 class.

Used for controlling an ISL1208 real time clock connected via I2C.

Example:

 #include "mbed.h"
 #include "ISL1208.h"

 ISL1208 rtc(p28, p27);

 int main()
 {
     //Try to open the ISL1208
     if (rtc.open()) {
         printf("Device detected!\n");

         //Configure the oscillator for a 32.768kHz crystal
         rtc.oscillatorMode(ISL1208::OSCILLATOR_CRYSTAL);

         //Check if we need to reset the time
         if (rtc.powerFailed()) {
             //The time has been lost due to a power complete power failure
             printf("Device has lost power! Resetting time...\n");

             //Set RTC time to Wed, 28 Oct 2009 11:35:37
             rtc.time(1256729737);
         }

         while(1) {
             //Get the current time
             time_t seconds = rtc.time();

             //Print the time in various formats
             printf("\nTime as seconds since January 1, 1970 = %d\n", seconds);
             printf("Time as a basic string = %s", ctime(&seconds));
             char buffer[32];
             strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
             printf("Time as a custom formatted string = %s", buffer);

             //Delay for 1.0 seconds
             wait(1.0);
         }
     } else {
         error("Device not detected!\n");
     }
 }

Definition at line 70 of file ISL1208.h.


Member Enumeration Documentation

enum AlarmMode

Represents the alarm mode of the ISL1208.

Enumerator:
ALARM_DISABLED 

The alarm function is disabled.

ALARM_SINGLE 

Only a one-time match will be made between the RTC and alarm registers, and the IRQ/fOUT pin will pull low until the alarm flag is cleared.

ALARM_INTERRUPT 

Every time an alarm match is made the IRQ/fOUT pin will pull low for 250ms, the alarm flag does not have to be cleared.

Definition at line 110 of file ISL1208.h.

Represents the different battery mode ATR selections of the ISL1208.

Enumerator:
BMATR_ZERO 

Delta capacitance = 0pF.

BMATR_MINUS_0_5 

Delta capacitance = -0.5pF (≈ +2ppm)

BMATR_PLUS_0_5 

Delta capacitance = +0.5pF (≈ -2ppm)

BMATR_PLUS_1_0 

Delta capacitance = +1pF (≈ -4ppm)

Definition at line 118 of file ISL1208.h.

Represents the different digital trim selections of the ISL1208.

Enumerator:
DTR_ZERO 

Digital trim = 0ppm.

DTR_PLUS_20 

Digital trim = ≈ +20ppm.

DTR_PLUS_40 

Digital trim = ≈ +40ppm.

DTR_PLUS_60 

Digital trim = ≈ +60ppm.

DTR_MINUS_20 

Digital trim = ≈ -20ppm.

DTR_MINUS_40 

Digital trim = ≈ -40ppm.

DTR_MINUS_60 

Digital trim = ≈ -60ppm.

Definition at line 127 of file ISL1208.h.

Represents the different oscillator modes for the ISL1208.

Enumerator:
OSCILLATOR_CRYSTAL 

The internal crystal oscillator is enabled.

OSCILLATOR_EXTERNAL 

The internal crystal oscillator is disabled, an external 32kHz oscillator is connected to X1.

Definition at line 75 of file ISL1208.h.

Represents the different output frequencies for the IRQ/fOUT pin on the ISL1208.

Enumerator:
FOUT_DISABLED 

Disable frequency generation on the IRQ/fOUT pin.

FOUT_32768_HZ 

Generate 32.768kHz on the IRQ/fOUT pin.

FOUT_4096_HZ 

Generate 4.096kHz on the IRQ/fOUT pin.

FOUT_1024_HZ 

Generate 1.024kHz on the IRQ/fOUT pin.

FOUT_64_HZ 

Generate 64Hz on the IRQ/fOUT pin.

FOUT_32_HZ 

Generate 32Hz on the IRQ/fOUT pin.

FOUT_16_HZ 

Generate 16Hz on the IRQ/fOUT pin.

FOUT_8_HZ 

Generate 8Hz on the IRQ/fOUT pin.

FOUT_4_HZ 

Generate 4Hz on the IRQ/fOUT pin.

FOUT_2_HZ 

Generate 2Hz on the IRQ/fOUT pin.

FOUT_1_HZ 

Generate 1Hz on the IRQ/fOUT pin.

FOUT_1_2_HZ 

Generate 1/2Hz on the IRQ/fOUT pin.

FOUT_1_4_HZ 

Generate 1/4Hz on the IRQ/fOUT pin.

FOUT_1_8_HZ 

Generate 1/8Hz on the IRQ/fOUT pin.

FOUT_1_16_HZ 

Generate 1/16Hz on the IRQ/fOUT pin.

FOUT_1_32_HZ 

Generate 1/32Hz on the IRQ/fOUT pin.

Definition at line 82 of file ISL1208.h.

enum PowerMode

Represents the power mode of the ISL1208.

Enumerator:
POWER_NORMAL 

VBAT supply will be used when VDD < VBAT - VBATHYS and VDD < VTRIP.

POWER_LPMODE 

VBAT supply will be used when VDD < VBAT - VBATHYS.

Definition at line 103 of file ISL1208.h.


Constructor & Destructor Documentation

ISL1208 ( PinName  sda,
PinName  scl,
int  hz = 400000 
)

Create a ISL1208 object connected to the specified I2C pins.

Parameters:
sdaThe I2C data pin.
sclThe I2C clock pin.
hzThe I2C bus frequency (defaults to 400kHz).

Definition at line 21 of file ISL1208.cpp.


Member Function Documentation

bool alarmFlag (  )

Determine whether the alarm has matched the RTC.

Returns:
Whether or not the alarm has matched the RTC.

Definition at line 146 of file ISL1208.cpp.

ISL1208::AlarmMode alarmMode (  )

Get the current alarm mode of the ISL1208.

Returns:
The current alarm mode as an AlarmMode enum.

Definition at line 275 of file ISL1208.cpp.

void alarmMode ( AlarmMode  mode )

Set the alarm mode of the ISL1208.

Parameters:
modeThe new alarm mode as an AlarmMode enum.

Definition at line 290 of file ISL1208.cpp.

time_t alarmTime (  )

Get the alarm time from the ISL1208.

Returns:
The current alarm time as a Unix timestamp (with the current year)

Definition at line 411 of file ISL1208.cpp.

void alarmTime ( time_t  t,
bool  sc = true,
bool  mn = true,
bool  hr = true,
bool  dt = true,
bool  mo = true,
bool  dw = true 
)

Set the alarm time on the ISL1208 from a Unix timestamp.

Parameters:
tThe alarm time as a Unix timestamp.
scEnable or disable seconds matching.
mnEnable or disable minutes matching.
hrEnable or disable hours matching.
dtEnable or disable date matching.
moEnable or disable month matching.
dwEnable or disable day of week matching.

Definition at line 431 of file ISL1208.cpp.

float analogTrim (  )

Get the current analog trim of the ISL1208.

Returns:
The current analog trim in pF.

Definition at line 309 of file ISL1208.cpp.

void analogTrim ( float  trim )

Set the analog trim of the ISL1208.

Parameters:
trimThe new analog trim in pF (valid range 4.5pF to 20.25pF in 0.25pF steps).

Definition at line 327 of file ISL1208.cpp.

bool batteryFlag (  )

Determine whether the RTC has been on battery backup.

Returns:
Whether or not the RTC has been on battery backup.

Definition at line 122 of file ISL1208.cpp.

ISL1208::BatteryModeATR batteryModeATR (  )

Get the current battery mode analog trim of the ISL1208.

Returns:
The current battery mode analog trim as a BatteryModeATR enum.

Definition at line 357 of file ISL1208.cpp.

void batteryModeATR ( BatteryModeATR  atr )

Set the battery mode analog trim of the ISL1208.

Parameters:
modeThe new battery mode analog trim as a BatteryModeATR enum.

Definition at line 369 of file ISL1208.cpp.

void clearAlarmFlag (  )

Clear the alarm flag.

Definition at line 158 of file ISL1208.cpp.

void clearBatteryFlag (  )

Clear the battery backup flag.

Definition at line 134 of file ISL1208.cpp.

ISL1208::DigitalTrim digitalTrim (  )

Get the current digital trim of the ISL1208.

Returns:
The current digital trim as a DigitalTrim enum.

Definition at line 384 of file ISL1208.cpp.

void digitalTrim ( DigitalTrim  dtr )

Set the digital trim of the ISL1208.

Parameters:
modeThe new digital trim as a DigitalTrim enum.

Definition at line 396 of file ISL1208.cpp.

ISL1208::OutputFrequency foutFrequency (  )

Get the current output frequency on the IRQ/fOUT pin.

Returns:
The current output frequency.

Definition at line 197 of file ISL1208.cpp.

void foutFrequency ( OutputFrequency  freq )

Set the output frequency on the IRQ/fOUT pin.

Parameters:
freqThe new output frequency.

Definition at line 206 of file ISL1208.cpp.

bool open (  )

Probe for the ISL1208 and configure auto reset if present.

Returns:
'true' if the device exists on the bus, 'false' if the device doesn't exist on the bus.

Definition at line 27 of file ISL1208.cpp.

ISL1208::OscillatorMode oscillatorMode (  )

Get the current oscillator mode of the ISL1208.

Returns:
The current oscillator mode as a OscillatorMode enum.

Definition at line 170 of file ISL1208.cpp.

void oscillatorMode ( OscillatorMode  mode )

Set the oscillator mode of the ISL1208.

Parameters:
modeThe new oscillator mode as a OscillatorMode enum.

Definition at line 182 of file ISL1208.cpp.

bool outputOnBattery (  )

Determine whether or not the IRQ/fOUT pin will continue to output on battery power.

Returns:
Whether or not the IRQ/fOUT pin will continue to output on battery power.

Definition at line 221 of file ISL1208.cpp.

void outputOnBattery ( bool  output )

Set whether or not the IRQ/fOUT pin should continue to output on battery power.

Parameters:
outputWhether or not the IRQ/fOUT pin should continue to output on battery power.

Definition at line 233 of file ISL1208.cpp.

bool powerFailed (  )

Determine whether the RTC has completely lost power (and hence the time and SRAM)

Returns:
Whether or not the RTC has completely lost power.

Definition at line 110 of file ISL1208.cpp.

ISL1208::PowerMode powerMode (  )

Get the current power mode of the ISL1208.

Returns:
The current power mode as a PowerMode enum.

Definition at line 248 of file ISL1208.cpp.

void powerMode ( PowerMode  mode )

Set the power mode of the ISL1208.

Parameters:
modeThe new power mode as a PowerMode enum.

Definition at line 260 of file ISL1208.cpp.

void sram ( unsigned short  data )

Write new data to the battery-backed SRAM.

Parameters:
dataThe new data for the SRAM.

Definition at line 469 of file ISL1208.cpp.

unsigned short sram (  )

Read the contents of the battery-backed SRAM.

Returns:
The current contents of the SRAM.

Definition at line 463 of file ISL1208.cpp.

time_t time (  )

Get the current time from the ISL1208.

Returns:
The current time as a Unix timestamp.

Definition at line 48 of file ISL1208.cpp.

void time ( time_t  t )

Set the current time on the ISL1208 from a Unix timestamp.

Parameters:
tThe current time as a Unix timestamp.

Definition at line 79 of file ISL1208.cpp.