Hi, I have a 18F452 running @20Mhz with a 20MHz crystal; a HD44780 LCD in 4 bit mode connected to PORTD and PORTE a LED connected to PORTB.7 I have also a DS1307 connected through I2C to the 18F452 with 10k pullups at 100khz what I am seeing.. - without ds1307 functions are not called, I don't get a Square Wave output from the DS1307 -- fine. - when ds1307_init() is called, I do get a Square Wave output from the DS1307 -- fine. - when ds1307_read() is called, the LED is lit up completely indicating that MSSP is waiting for the Buffer to be full (BF) indefinitely. Now, If I don't look for that BF(Buffer Full) flag, all what I get from the ds1307_read() is 0xff Any Ideas, as to what could possibly be wrong in my code ? Thanks, Manu #include #include #include #include "delay.h" #include "LCD.h" #pragma config OSC =3D HS #pragma config PWRT =3D ON #pragma config WDT =3D OFF #pragma config LVP =3D OFF #define LED_PIN PORTBbits.RB7 void ds1307_write(unsigned char reg, unsigned char data) { unsigned char stat; IdleI2C(); /* wait for an idle bus */ StartI2C(); /* send START bit */ while (SSPCON2bits.SEN); /* wait till START is sent */ WriteI2C(0xd0); /* DS1307 I2C address */ AckI2C(); /* Slave ACK */ WriteI2C(reg); /* Slave register address */ AckI2C(); WriteI2C(data); /* data */ AckI2C(); StopI2C(); while (SSPCON2bits.PEN); /* wait till STOP is sent */ } void ds1307_read(unsigned char reg, unsigned char *data) { unsigned char i; IdleI2C(); StartI2C(); while (SSPCON2.bits.SEN); WriteI2C(0xd0); AckI2C(); WriteI2C(0x00); AckI2C(); StartI2C(); while (SSPCON2bits.SEN); WriteI2C(0xd1); AckI2C(); while (!SSPSTATbits.BF) { LED_PIN =3D 0; } LED_PIN =3D 1 *data =3D ReadI2C(); StopI2C(); while (SSPCON2bits.PEN); } #define DS1307_CTL_OUT (1 << 7) #define DS1307_CTL_SQWE (1 << 4) #define DS1307_1Hz (DS1307_CTL_OUT | DS1307_CTL_SQWE) void ds1307_init(void) { ds1307_write(0x00, 0x00); /* enable oscillator*/ ds1307_write(0x07, DS1307_1Hz); } void main(void) { TRISB =3D 0x00; TRISD =3D 0x00; TRISE =3D 0x00; ADCON1 =3D 0x0f; LED_PIN =3D 1; /* LED off */ lcd_init(); send_cmd(0x0c); /* turn OFF cursor */ OpenI2C(MASTER, SLEW_OFF); /* I2C Master */ SSPADD =3D 49; /* 100khz @ 20MHz */ ds1307_init(); set_cursor(1, 1); /* set cursor to R:1 C:1 */ printf("-- DS1307 --"); set_cursor(2, 1); while(1) { ds1307_read(0x00, &val); printf("S:%d ", val); LED_PIN =3D ~LED_PIN; /* blink LED */ delay250ms(); } } --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .