InetrfaceProducts NXP / PCF2127

Dependents:   PCF2127_Demo PCF2127_Hello

Embed: (wiki syntax)

« Back to documentation index

PCF2127 Class Reference

PCF2127 Class Reference

PCF2127 class. More...

#include <PCF2127.h>

Public Types

enum  RegisterName
 

name of the PCF2127 registers

More...
enum  ErrorNum
 

Error code.

More...

Public Member Functions

 PCF2127 (PinName sda, PinName sdl, char vControl_1=Cntl1, char vControl_2=Cntl2, char vControl_3=Cntl1, char vCLKOUT_ctl=ClkOut)
 Create a PCF2127 instance connected to specified I2C pins with specified address.
 PCF2127 (I2C &i2c, char vControl_1=Cntl1, char vControl_2=Cntl2, char vControl_3=Cntl1, char vCLKOUT_ctl=ClkOut)
 Create a PCF2127 instance connected to specified I2C pins with specified address.
 ~PCF2127 ()
 Destractor.
int is_init_required (void)
 Clock integrity check.
int set_time (struct tm *dtp)
 Set the time.
int set_time (time_t *tp)
 Set the time.
int set_time (char *s)
 Set the time.
time_t time (time_t *tp)
 Get time of day.
int set_alarm (char addr, char s)
 Register access interface with integer to BCD conversion.
int clear_intr (void)
 Clear interrupt flag.
int RAM_write (int address, char *p, int size)
 Writing data into RAM (for PCF2127 only)
int RAM_read (int address, char *p, int size)
 Reading data from RAM (for PCF2127 only)

Detailed Description

PCF2127 class.

This is a driver code for the PPCF2127: "real time clock (RTC)" module which is including a Xtal and TCXO This class provides interface for PCF2127 operation and accessing its registers. Detail information is available on next URL. http://www.nxp.com/products/interface_and_connectivity/real_time_clocks/rtcs_with_temp_compensation/series/PCF2127.html

Example:

  #include "mbed.h"
  #include "PCF2127.h"
  
  PCF2127 rtc( p28, p27 );
  
  int main()
  {
      time_t  t;
      
      printf( "PCF2127 demo started.\r\n" );
  
      if ( rtc.is_init_required() ) {
          rtc.set_time( "2014 12 10 12 00 00" );
      }
  
      while ( 1 ) {
          t   = rtc.time( NULL );
          printf( "%s\r", ctime( &t ) );
          wait( 0.25 );
      }
  }

Definition at line 56 of file PCF2127.h.


Member Enumeration Documentation

enum ErrorNum

Error code.

Definition at line 96 of file PCF2127.h.

name of the PCF2127 registers

Definition at line 61 of file PCF2127.h.


Constructor & Destructor Documentation

PCF2127 ( PinName  sda,
PinName  sdl,
char  vControl_1 = Cntl1,
char  vControl_2 = Cntl2,
char  vControl_3 = Cntl1,
char  vCLKOUT_ctl = ClkOut 
)

Create a PCF2127 instance connected to specified I2C pins with specified address.

Parameters:
I2C_sdaI2C-bus SDA pin
I2C_sclI2C-bus SCL pin
vControl_1(option) data for Control_1 register (default setting generates interrupts by second and minute)
vControl_2(option) data for Control_2 register
vControl_3(option) data for Control_3 register (default setting of battery switch-over function as standard mode)
vCLKOUT_ctl(option) data for CLKOUT_ctl register (default setting 1Hz output on CLKOUT pin) CLKOUT_ctl

Definition at line 23 of file PCF2127.cpp.

PCF2127 ( I2C &  i2c,
char  vControl_1 = Cntl1,
char  vControl_2 = Cntl2,
char  vControl_3 = Cntl1,
char  vCLKOUT_ctl = ClkOut 
)

Create a PCF2127 instance connected to specified I2C pins with specified address.

Parameters:
i2cI2C object (instance)
vControl_1(option) data for Control_1 register (default setting generates interrupts by second and minute)
vControl_2(option) data for Control_2 register
vControl_3(option) data for Control_3 register (default setting of battery switch-over function as standard mode)
vCLKOUT_ctl(option) data for CLKOUT_ctl register (default setting 1Hz output on CLKOUT pin)

Definition at line 29 of file PCF2127.cpp.

~PCF2127 (  )

Destractor.

Definition at line 35 of file PCF2127.cpp.


Member Function Documentation

int clear_intr ( void   )

Clear interrupt flag.

Clears interrupt flags by writing 0x00 into Control_2 register

Returns:
Error code (NO_ERROR==0)

Definition at line 145 of file PCF2127.cpp.

int is_init_required ( void   )

Clock integrity check.

Returns:
non-zero value if the clock was stopped (means need to set the time)

Definition at line 57 of file PCF2127.cpp.

int RAM_read ( int  address,
char *  p,
int  size 
)

Reading data from RAM (for PCF2127 only)

Read data from PCF2127 internal RAM

Parameters:
addresstarget address of internal RAM
*ppointer to read data buffer
sizesize of writing data
Returns:
Error code (NO_ERROR==0)

Definition at line 165 of file PCF2127.cpp.

int RAM_write ( int  address,
char *  p,
int  size 
)

Writing data into RAM (for PCF2127 only)

Write data into PCF2127 internal RAM

Parameters:
addresstarget address of internal RAM
*ppointer to write data buffer
sizesize of writing data
Returns:
Error code (NO_ERROR==0)

Definition at line 150 of file PCF2127.cpp.

int set_alarm ( char  addr,
char  s 
)

Register access interface with integer to BCD conversion.

Parameters:
addrRegister address
sInteger data. Converted to BCD before writing inot the register.
Returns:
Error code (NO_ERROR==0)

Definition at line 136 of file PCF2127.cpp.

int set_time ( struct tm *  dtp )

Set the time.

Parameters:
dtpPointer to struct tm
Returns:
Error code (NO_ERROR==0)

Definition at line 62 of file PCF2127.cpp.

int set_time ( char *  s )

Set the time.

Parameters:
sString data: The time information should be given in format of "YYYY MM DD HH MM SS"
Returns:
Error code (NO_ERROR==0)

Definition at line 86 of file PCF2127.cpp.

int set_time ( time_t *  tp )

Set the time.

Parameters:
tppointer to time_t
Returns:
Error code (NO_ERROR==0)

Definition at line 81 of file PCF2127.cpp.

time_t time ( time_t *  tp )

Get time of day.

This function works similar to "time()" in standard-C-library

Parameters:
tpPointer to time_t
Returns:
Error code (NO_ERROR==0)

Definition at line 104 of file PCF2127.cpp.