Stuck with RTC on I2C.

Yeah, I probably deserve this.

I have two different types of RTC units.

Running I2C scanner one shows up on address 68 (or 50) and the other is on 51…

I remember going through this as I have just tried to help someone else with a problem I had.

Don’ t you have to set the RTC address - with a bit shift - somewhere in the code?

I can’t seem to get to save the time to the RTC units. Either of them.

One is using a 1307 and the other is a 8583.

Please, anyone?

Why are you stuck ?
The Arduino Wire library uses the 7-bits (shifted) i2c-address.
Run the i2c_scanner and if it finds 0x68 and 0x69, you need to use Wire.begin(0x68); and Wire.begin(0x69);
Some manufacturers use the 8-bits (unshifted) i2c-address in the datasheet, but just ignore that and use the i2c_scanner.
It is really that simple.
http://playground.arduino.cc/Main/I2cScanner

I have two different types of RTC units.

What kind are they?

Pete

Well,

This may be where I am falling down:

In the sketches I have used and which work, they:
#include "DS1307_1.h"

so the "DS1307_1.h" file is in that directory.

Though I have noticed that there is also a DS1307 directory in the librarys folder too.

I don't know why.

But I am working on a new sketch and it too has its own DS1307 files.

In said files there is a line:
#define DS1307_CTRL_ID B1101000 //DS1307

in the .h file.

Ok...... Just shot myself in the foot.

Thing is I have a couple of these "Tiny RTC" units - yeah: read about them.......

And I also have a 8583 RTC unit.

Alas its code is error ridden with "byte" in the .h file which are not liked.

So I can't test it. (Just realised that now. Wondering why the 1307 wasn't working with the 8583 chip.)

So I am annoyed/confused to what is going on.

I can run the 1307 test sketch and "set the time" but when I reset it, the time restores to the initial weird date.
It is valid, but just WAY in the future.

The battery is ok. Checked it with a DMM. 3.8 volts.

I have a few days off work and though I would put them to good use on the Arduino projects I have going.

Seems I am getting nowhere fast!

el_supremo:

I have two different types of RTC units.

What kind are they?

Pete

Pete,

One is a "Tiny RTC" and one is a 8583 board:
http://www.futurlec.com.au/Mini_PCF8583.jsp

I just realised that they won't work with the same sketches and when I tried to load the 8583's sketch it has a problem with "BYTE" in the .h file.

This is the .h file:

These are the initial problems:
int bcd_to_byte(byte bcd);
byte int_to_bcd(int in);

Near the bottom.

But there are heaps more I believe.

/*
  Implements a simple interface to the time function of the PCF8583 RTC chip

  Works around the device's limited year storage by keeping the year in the
  first two bytes of user accessible storage

  Assumes device is attached in the standard location - Analog pins 4 and 5
  Device address is the 8 bit address (as in the device datasheet - normally A0)

  Copyright (c) 2009, Erik DeBill


  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/


/*

   Usage:
      PCF8583 pcf(0xA0);
      pcf.get_time();

      Serial.print("year: ");
      Serial.println(pcf.year);


      pcf.hour = 14;
      pcf.minute = 30
      pcf.second = 0
      pcf.year = 2009
      pcf.month = 9
      pcf.day = 12
      pcf.set_time();


*/

#ifndef PCF8583_H
#define PCF8583_H

#include <WProgram.h>
#include <../Wire/Wire.h>

class PCF8583 {
    int address;
  public:
 
    int milisec_A;
    int second_A;
    int minute_A;
    int hour_A;
    int day_A;
    int second;
    int minute;
    int hour;
    int day;
    int month;
    int year;
    int year_base;
    int timmer;

    PCF8583(int device_address);
    void init ();
    
    void get_time();
    void set_time();
    void get_alarm();
    void set_daily_alarm();
    int bcd_to_byte(byte bcd);
    byte int_to_bcd(int in);


};


#endif  //PCF8583_H

Folks,

All working.

Found the problem/s.

I'm a step further forward now.

lost_and_confused:
Folks,

All working.

Found the problem/s.

I'm a step further forward now.

Are you going to share what the solution to your problem was, so other people can benefit from your posts ?

// Per.

Well,

The 8583 problem was resolved by me finding a working sketch and a bit of hacking.
The library was outdated and someone helped me with the how to make the older library working.

The other RTC is still not working as it is one of those "TINY RTC" boards.

Ok folks,
I’m really stuck.

This is a sketch I am trying to bash together to set/read the 1307 RTC chip.

Other sketches “bit bash” with the wire.h and I don’t know if that is part of another problem.

As I have a working sketch with a 1307 RTC (and all works) I am trying to get this sketch working.

Alas
Serial_clock:40: error: ‘DS1307’ does not name a type

Means nothing to me.

Sketch attached below.
I’ll try to work out what that error means, but in the mean time…

Serial_clock.zip (6.18 KB)