I’d remove as many variables as possible. Power the Stalker directly from USB, keep the voltage constant. See if your code still hangs or gets bad date randomly. It might be software.
The RTC is accessed via i2c, so you’d just read from it or write to it like any other i2c device.
[code]#define DS1307_I2C_ADDRESS 0x68
int bcd_to_decimal( int bcd )
{
return ((bcd >> 4) * 10) + (bcd % 16);
}
void DS1307::update( void )
{
Wire.beginTransmission( DS1307_I2C_ADDRESS );
Wire.send( 0x00 );
Wire.endTransmission( );
Wire.requestFrom( DS1307_I2C_ADDRESS, 7 );
second = bcd_to_decimal( Wire.receive( ) & 0x7F );
minute = bcd_to_decimal( Wire.receive( ) );
hour = bcd_to_decimal( Wire.receive( ) & 0x3F );
day_of_week = bcd_to_decimal( Wire.receive( ) );
day_of_month = bcd_to_decimal( Wire.receive( ) );
month = bcd_to_decimal( Wire.receive( ) );
year = bcd_to_decimal( Wire.receive( ) );
hour_12 = ( hour > 12 ) ? (hour - 12) : hour;
}
[/code]