I2C stuck in read
Discussion in "Project Doubts" started by JaguarPaw Dec 13, 2016.
Tue Dec 13 2016, 03:13 am
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.
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.
Fri Dec 16 2016, 08:03 pm
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;
{
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
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 ?
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 ?
Powered by e107 Forum System