Discussion in "Project Doubts" started by    JaguarPaw    Dec 13, 2016.
Tue Dec 13 2016, 03:13 am
#1
I have used the I2C library and followed the tutorial.
I am using a DS1307 and a PIC16f1829 with the xc8 compiler.

I have pull up resistors

About 7/10 times i attempt to read the DS1307 it gets stuck here while(!SSP1STATbits.BF);
in the read routine.
I have had succesfull reads be as mentioned before only about 3/10 times.
Tue Dec 13 2016, 02:22 pm
#2
can you post your code snippet? are you calling with NAK at last byte read?
 JaguarPaw like this.
Fri Dec 16 2016, 08:03 pm
#3
while (1)
{
I2CStart ();
I2CSend(0xD0);
I2CSend(0x00);
I2CRestart();
I2CSend(0xD1);
r = I2CRead();

for (i = 8; i > 0; i--)
{
/* read a byte */
I2CData[i] = I2CRead();

if (i - 1)
I2CAck();
else
I2CNak();
}
/* Send stop */
I2CStop();

}
}

the r variable would successfully store the number returned back from the ds1307 as it was originally working
now it will freeze where i stated before or return null

here is the set up code. the subroutines are the same as on this website.
void main(void)
{
// Oscillator configuration

// SCS FOSC; SPLLEN disabled; IRCF 8MHz_HF;
OSCCON = 0x70;
// LFIOFR disabled; HFIOFL not stable; OSTS intosc; PLLR disabled; HFIOFS not stable; HFIOFR disabled; MFIOFR disabled; T1OSCR disabled;
OSCSTAT = 0x00;
// TUN 0;
OSCTUNE = 0x00;
// Set the secondary oscillator

// Wait for PLL to stabilize
while(PLLR == 0)
{
}

// Pin configuration

ANSELB = 0;
TRISBbits.TRISB4 = 1;
TRISBbits.TRISB6 = 1;
//SSP1STATbits.SMP = 0;

SSP1STAT = 0x80;
// SSPEN enabled; WCOL no_collision; CKP Idle:Low, Active:High; SSPM FOSC/4_SSPxADD_I2C; SSPOV no_overflow;
SSP1CON1 = 0x28;
// ACKTIM ackseq; SBCDE disabled; BOEN disabled; SCIE disabled; PCIE disabled; DHEN disabled; SDAHT 100ns; AHEN disabled;
SSP1CON3 = 0x00;
// Baud Rate Generator Value: SSPADD 79;
SSP1ADD = 0x4f;
Thu Dec 22 2016, 02:37 am
#4
Have you made any progress ?

It sounds as if your hardware is on the edge of working /not working.
What pull up resitors are you using ?
Do you have a good ,clean power supply and good ground connections between the
PIC and the 1307.

If you power off the board each time , and stop after the first read (r = I2CRead();)
how reliably does it read ?




Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am