Hi Colin, On Fri, Feb 18, 2011 at 5:26 PM, cdb wrote: > Manu, > > I have working code for the DS1337 which is the 1307 with internal crysta= l. > > I haven't used the hardware I2C so at first glance I can't say whether yo= u > have a =A0problem there, but your init code is very different to mine. > > :: void ds1307_init(void) > :: { > :: =A0 =A0 =A0 =A0ds1307_write(0x00, 0x00); /* enable oscillator*/ > > :: =A0 =A0 =A0 =A0ds1307_write(0x07, DS1307_1Hz); > > Whilst I also set the time (which you don't have to, if I recall correctl= y > you have to send an extra initialisation sequence. My code (not in C but = in > XCSB basic is below) > > /************************************************************************= ** > *; > **DS1337 automatically increments its' registers. > ** > *************************************************************************= ** > */ > > proc ubyte init_rtc_1337() > > ubyte I2C_status > > =A0I2C_master_write_start_condition() > =A0I2C_status =3D I2C_master_write_byte(WRITE_TO_SLV) > > =A0if I2C_status !=3D 0 then > > =A0 =A0 =A0 =A0 I2C_status =3D I2C_master_write_byte(DS1337_CNTRL_REG) //= send control > register address > =A0 =A0 =A0 =A0 I2C_status =3D I2C_master_write_byte(DS1337_CNTRL_INIT)//= send control > string > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 I2C_status =3D I2C_master_write_byte(DS13= 37_STATUS_INIT)//clear status > register > =A0 =A0 =A0 =A0 I2C_status =3D rtc_write(&rtc,DS1337_REG_NUM) =A0 =A0 =A0= =A0 =A0 =A0//send time data to RTC > =A0 =A0 =A0 =A0 I2C_master_write_stop_condition() > > =A0 =A0 =A0 =A0endif > > =A0return I2C_status > > endproc > > Where: > > /************************************************************************= ** > ***; > ** =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0DS1337 specific, constant declarations. > ** > *************************************************************************= ** > ***/ > > const DS1337_ADD =3D 0b_01101000 > const WRITE_TO_SLV =3D DS1337_ADD << 1 > const READ_SLV =3D WRITE_TO_SLV + 1 > const DS1337_REG_NUM =3D 0x07 // > const DS1337_BASE_REG =3D 0x00 //Seconds register. Chip auto-increments t= o > next register and rolls over at 0x0f > > const DS1337_SET_T =3D DS1337_BASE_REG + 1 > const DS1337_SET_A =3D 0x0B > //const DS1337_ALARM_1_REG =3D 0x04 > //const DS1337_ALARM_2_REG =3D 0x03 > const DS1337_CNTRL_REG =3D 0x0E > const DS1337_STATUS_REG =3D 0x0F > const DS1337_CNTRL_INIT =3D 0x00 > const DS1337_STATUS_INIT =3D 0x00 > > I'll have a closer look after I've got some sleep. > > Colin Thanks for your input. - The DS1307 and DS1337 are slightly different in terms of the registers on them, - but the I2C communication sequences on both of them are identical. - The DS1307 has an oscillator enable bit at 0x00 while the DS1337 has it at 0x0e - The DS1307 doesn't have the Alarm functionality of the DS1337 - Now there is the DS1337C which has a builtin crystal oscillator in comparison to the vanilla DS1337 ? Now, I fail to understand your init_rtc_1337() You do: - Master send START - Master Write DS1337_ADD - Master Write 0x0e - Master Write 0x00 - Master Write 7 bytes ??? All what you need to do is to enable the oscillator to initialize the RTC. Writing to the other registers are optional, which is for setting up time etc. I don't see how that affects the reads ? I can't identify what I am doing wrong, but ... Thanks, Manu --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .