RX8025 library updated for IDE 1.0

I want to share with you an RX8025 library updated for IDE 1.0

cpp

#include <Wire.h>
#include "RX8025.h"
//********************************************************************

//===============================================
#define  RX8025_address  0x32

unsigned char RX8025_Control[2]=
{
  0x20,0x00
};

//===============================================
void setRtcTime(void)
{
  Wire.beginTransmission(RX8025_address);
  Wire.print(0x00);
  for(unsigned char i=0; i<7; i++)
  {
    Wire.write(RX8025_time[i]);
  }
  Wire.endTransmission();
}

//===============================================
uint8_t bcd2bin (uint8_t val) 
{ 
  return val - 6 * (val >> 4); 
}

uint8_t bin2bcd (uint8_t val) 
{ 
  return val + 6 * (val / 10); 
}

//===============================================
void getRtcTime(void)
{
  unsigned char i=0;
  Wire.beginTransmission(RX8025_address);
  Wire.print(0x00);
  Wire.endTransmission();//
  Wire.requestFrom(RX8025_address,8);
  RX8025_time[i]= Wire.read();//not use
  while(Wire.available())
  { 
    RX8025_time[i]= Wire.read();
    i++;
  }
  Wire.endTransmission();//

  year   = bcd2bin(RX8025_time[6]&0xff);
  month  = bcd2bin(RX8025_time[5]&0x1f);
  date   = bcd2bin(RX8025_time[4]&0x3f);
  week   = bcd2bin(RX8025_time[3]&0x07);
  hour   = bcd2bin(RX8025_time[2]&0x3f);
  minute = bcd2bin(RX8025_time[1]&0x7f);
  second = bcd2bin(RX8025_time[0]&0x7f);
}

//===============================================
void RX8025_init(void)
{
  Wire.begin();
  Wire.beginTransmission(RX8025_address);//clear power on reset flag, set to 24hr format
  Wire.write(0xe0);
  for(unsigned char i=0; i<2; i++)
  {
    Wire.write(RX8025_Control[i]);
  }
  Wire.endTransmission();
  //setRtcTime();
}

.h

#ifndef RX8025_h
#define RX8025_h

#define RX8025_SEC      0
#define RX8025_MIN      1
#define RX8025_HR       2
#define RX8025_WEEK     3
#define RX8025_DATE     4
#define RX8025_MTH      5
#define RX8025_YR       6
#define RX8025_Doffset  7
#define RX8025_AW_MIN   8
#define RX8025_AW_HR    9
#define RX8025_AW_WEEK  10
#define RX8025_AD_MIN   11
#define RX8025_AD_HR    12
#define RX8025_CTL1     14
#define RX8025_CTL2     15

extern unsigned char RX8025_time[7];

extern unsigned char hour;
extern unsigned char minute;
extern unsigned char second;
extern unsigned char week;
extern unsigned char year;
extern unsigned char month;
extern unsigned char date;


void RX8025_init(void);
void getRtcTime(void);
void setRtcTime(void);

#endif

So I am trying to get this to work for me but I keep getting the following error.

RX8025_test.cpp: In function 'void setup()':
RX8025_test.pde:-1: error: 'RX8025' was not declared in this scope
RX8025_test.cpp: In function 'void loop()':
RX8025_test.pde:-1: error: 'RX8025' was not declared in this scope

sacredbandofthebes:
So I am trying to get this to work for me but I keep getting the following error.

RX8025_test.cpp: In function 'void setup()':
RX8025_test.pde:-1: error: 'RX8025' was not declared in this scope
RX8025_test.cpp: In function 'void loop()':
RX8025_test.pde:-1: error: 'RX8025' was not declared in this scope

Did you remember the include file?

So I have it semi working. as in I am able to set the time of the RTC. The following is my code to set and display the time.

#include <Wire.h>
#include "RX8025.h"

/*
  AnalogReadSerial
 Reads an analog input on pin 0, prints the result to the serial monitor 
 
 This example code is in the public domain.
 */
 unsigned char hour;
 unsigned char minute;
 unsigned char second;
 unsigned char week;
 unsigned char year;
 unsigned char month;
 unsigned char date;
 unsigned char RX8025_time[7]={01,10,9,15,13,4,12};
void setup() {
  Serial.begin(9600);
  RX8025_init();
  setRtcTime();
}

void loop() {
  getRtcTime();
  Serial.print(hour);
  printDigits(minute);
  printDigits(second);
  Serial.print(" ");
  Serial.print(date);
  Serial.print(" ");
  Serial.print(month);
  Serial.print(" ");
  Serial.print(year); 
  Serial.println(); 
  delay(1000);
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

however when it prints out it gives a weird number for seconds and it does not increment the time, such as the following:

9:10:85 13 4 12
9:10:85 13 4 12
9:10:85 13 4 12
9:10:85 13 4 12
9:10:85 13 4 12
9:10:85 13 4 12
9:10:85 13 4 12
9:10:85 13 4 12
9:10:85 13 4 12
9:10:85 13 4 12
9:10:85 13 4 12
9:10:85 13 4 12
9:10:85 13 4 12
9:10:85 13 4 12

any advice on this would be much appreciated.

I don't know why that does not work for you, for me it works fine. I have done another version using C++ classes. you can try it:

INO example

//11-5-2012 Paolo Cantore, based on a seedstudio example


#include <Wire.h>
#include "mioRX8025.h"
#include "Arduino.h"

mioRX8025 rtc;

unsigned char hour=0;
unsigned char minute=0;
unsigned char second=0;
unsigned char week=0;
unsigned char year=0;
unsigned char month=0;
unsigned char date=0;




void setup(void)
{
  rtc.RX8025_time[0]=(unsigned char) 0x00; //second
  rtc.RX8025_time[1]=(unsigned char) 0x32; //minute
  rtc.RX8025_time[2]=(unsigned char) 0x09; //hour
  rtc.RX8025_time[3]=(unsigned char) 0x06; //day of week
  rtc.RX8025_time[4]=(unsigned char) 0x11; //date
  rtc.RX8025_time[5]=(unsigned char) 0x05; //month
  rtc.RX8025_time[6]=(unsigned char) 0x12; //year BCD format

  
  
  Serial.begin(9600);
  Serial.println("on the setup");
  rtc.RX8025_init();  
  rtc.setRtcTime(); //solo per settare la prima volta
}

void loop(void)
{

    rtc.getRtcTime();

    
    
  Serial.print(rtc.year,DEC);
  Serial.print("/");
  Serial.print(rtc.month,DEC);
  Serial.print("/");
  Serial.println(rtc.date,DEC);
  
  Serial.print(rtc.hour,DEC);
  Serial.print(":");
  Serial.print(rtc.minute,DEC);
  Serial.print(":");
  Serial.println(rtc.second,DEC);
  
  
    delay(3000);
}

.H

//11-5-2012 Paolo Cantore, based on a seedstudio example

#ifndef mioRX8025_h
#define mioRX8025_h

#define RX8025_SEC      0
#define RX8025_MIN      1
#define RX8025_HR       2
#define RX8025_WEEK     3
#define RX8025_DATE     4
#define RX8025_MTH      5
#define RX8025_YR       6
#define RX8025_Doffset  7
#define RX8025_AW_MIN   8
#define RX8025_AW_HR    9
#define RX8025_AW_WEEK  10
#define RX8025_AD_MIN   11
#define RX8025_AD_HR    12
#define RX8025_CTL1     14
#define RX8025_CTL2     15



class mioRX8025
{
private:
	uint8_t bcd2bin (uint8_t val); 

	uint8_t bin2bcd (uint8_t val);
	
	
	unsigned char RX8025_Control[2];
	
public:
	 mioRX8025();							//costruttore       
	~mioRX8025();							//distruttore
	
	
	 unsigned char RX8025_time[7];

	 unsigned char hour;
	 unsigned char minute;
	 unsigned char second;
	 unsigned char week;
	 unsigned char year;
	 unsigned char month;
	 unsigned char date;


	void RX8025_init(void);
	void getRtcTime(void);
	void setRtcTime(void);
	
};

#endif

.CPP

#include <Wire.h>
#include "mioRX8025.h"
#include "Arduino.h"
//********************************************************************

//===============================================
#define  RX8025_address  0x32








mioRX8025::mioRX8025()	//costruttore
{
	 RX8025_Control[0]=0x20;
	 RX8025_Control[1]=0x00;
}
mioRX8025::~mioRX8025()	//costruttore
{
	
}




//===============================================
void mioRX8025::setRtcTime(void)
{
  Wire.beginTransmission(RX8025_address);
  Wire.write((byte)0x00);
  for(unsigned char i=0; i<7; i++)
  {
    Wire.write(RX8025_time[i]);
  }
  Wire.endTransmission();
}

//===============================================
uint8_t mioRX8025::bcd2bin (uint8_t val) 
{ 
  return val - 6 * (val >> 4); 
}

uint8_t mioRX8025::bin2bcd (uint8_t val) 
{ 
  return val + 6 * (val / 10); 
}

//===============================================
void mioRX8025::getRtcTime(void)
{
  unsigned char i=0;
  Wire.beginTransmission(RX8025_address);
  Wire.write((byte) 0x00);
  Wire.endTransmission();//
  Wire.requestFrom(RX8025_address,8);
  RX8025_time[i]= Wire.read();//not use
  while(Wire.available())
  { 
    RX8025_time[i]= Wire.read();
    i++;
  }
  Wire.endTransmission();//

  year   = bcd2bin(RX8025_time[6]&0xff);
  month  = bcd2bin(RX8025_time[5]&0x1f);
  date   = bcd2bin(RX8025_time[4]&0x3f);
  week   = bcd2bin(RX8025_time[3]&0x07);
  hour   = bcd2bin(RX8025_time[2]&0x3f);
  minute = bcd2bin(RX8025_time[1]&0x7f);
  second = bcd2bin(RX8025_time[0]&0x7f);
}

//===============================================
void mioRX8025::RX8025_init(void)
{
  Wire.begin();
  Wire.beginTransmission(RX8025_address);//clear power on reset flag, set to 24hr format
  Wire.write(0xe0);
  for(unsigned char i=0; i<2; i++)
  {
    Wire.write(RX8025_Control[i]);
  }
  
  Wire.endTransmission();
  //setRtcTime();
}

if you have problem also with this try to check how you physically connect the rtc to the microcontroller.

Hi guys

I have the same problem.
Do somebody know the solution of this?!?

I have tried both codes before and get 85 for the seconds everytime. :frowning:

I have saved my problem. It's reason was a failure in the wiring of the hardware.

The items I used were

an Arduino UNO
a RX-8025SA Clock Module
a coin cell (CR2032)
an SMD-TSOP Multiadapter
two 10k? resistors
and a 333nF Ceramic Condensator (a 100nF would be better)

The RX-8025 was soldered on the Multiadapter by me and all items were mounted on a patch panel.
The wiring map shows the RX 8025 on the Multiadapter. Be careful to solder every second pin to the pin you put into the patch panel, because otherwise you have to build bridges from the pins which are not connected to the panel to free pins in the other row.
I attached the wiring. It is working quite good. I post it, because I don't find a complete wiring map on the internet.
I hope it will help someone who has the same problem.