I started in on it again tonight and breadboarded the Arduino mini with the Arduino USB->Serial converter. I then wired up the Sparkfun Real Time Clock. I had previously soldered a two-hole female header to the ADC4/ADC5 pins on the mini and ran the RTC SDA line to ADC4 and RTC SCL to ADC5 of the mini. Of course I powered the clock as well.
I ported some code by combining Julian’s page and some of the PIC code that came with the RTC (I used that only for addresses, register numbers, and basic info on the RTC.)
The problem I’m having is identical to what I’ve seen before when I tried to do this and that is that the chip hangs in the Wire.begin().
In the case, tonight, I put a serial print before Wire.begin and one after. From the console, I only get to the one before… I see “Calling Wire.begin”, but not the print after Wire.begin.
Also of note, every few seconds, setup() gets called again - the chip must be going through a reset and I see my serial print before the Wire.begin.
I tried it with the clock disconnected from the ADC4/ADC5 lines. Same results.
I’m nearly 99% certain Wire is boned on an Arduino Mini.
You can pretty much ignore all the code I’ve written so far, though I’m posting it below, because it doesn’t ever get past the Wire.begin call from what I can tell.
#include <stdio.h>
#include <Wire.h>
// Landon Cox
// TWI (I2C) sketch to communicate with the Sparkfun RTC
// code loosely based on Julian's TWI page:
// http://research.techkwondo.com/blog/julian/279
// and SparkFun's PIC code to get register and address values
//
#define RTCADDRESS 0x00
//Read hours register
#define RDHR 2
//Read minutes register
#define RDMIN 1
//Read seconds register
#define RDSEC 0
//Read Day
#define RDDAY 3
//Read Date
#define RDDATE 4
//Read Month
#define RDMON 5
//Read Year
#define RDYR 6
void setup()
{
Serial.begin(9600);
Serial.println("Calling Wire.begin");
Wire.begin(); // join i2c bus (address optional for master)
Serial.println("Back from Wire.begin");
}
void loop()
{
Serial.print("Reading clock");
readclock();
delay(2000);
}
void readclock()
{
int hours=0, minutes=0, seconds=0;
char timestr[30];
hours = readregister(RDHR);
minutes = readregister(RDMIN);
seconds = readregister(RDSEC);
sprintf(timestr,"time %d:%d:%d\n", hours, minutes, seconds );
Serial.print(timestr);
}
int readregister(byte registernum)
{
int value=-1;
byte value_l=0, value_h=0;
Wire.beginTransmission(RTCADDRESS);
Wire.send(registernum);
Wire.endTransmission();
// Now do a transfer read
Wire.requestFrom(RTCADDRESS, 1);
if(Wire.available())
{
value_l = Wire.receive();
}
Wire.endTransmission();
value = value_h << 8 | value_l;
return value;
}