I'm having problems with the I2C module on the PIC24HJ256GP610A. My code (see snippet below) runs perfectly fine on the PIC24HJ256GP610 [note: not 610A]. I'm using the I2C bus for communicating with a DS1374 RTCC. But on the 610A, it gets stuck when polling the ACKSTAT bit when trying to write a value to the RTCC with I2C. Also, most of the time the RTCC value does not increment when reading the value via I2C (sometimes it does increment as it should). Any ideas? Is there a config bit/mode/setting difference between the 610 and 610A that deals with the I2C module? I've tried switching out the RTCC chip, and switching out processors. So, the only difference here is that the I2C communication works on the 610, and not on the 610A.
What are the differences between the 610 and 610A? Is the 610 an obsolete part that is no longer manufactured, or will it keep being manufactured?
A few things I've noticed when experimenting, probing the signals, and stepping through with the debugger:
1). The I2C clock goes high indefinitely on the to-be 20th transmitted bit, which is where it gets stuck polling the ACKSTAT bit if I pause the debugger. The first bit appears to be the start bit, then 9 more bits, then another start/stop bit, then 9 more bits, then the clock line goes high.
2). When the clock line gets stuck and using the watch window, the value in the I2C1STATbits register is 0x8008, which translates to received a NACK from the slave device, and that a Start (or Repeated Start) bit has been detected last.
3). I am always able to read from the slave device (RTCC) with both 610 and 610A. However, sometimes with the 610A its value does not increment and stays at some integer value. I believe when I cut off power to everything and reprogram everything, the RTCC value changes. Sometimes it stays constant when reading the value, and maybe 25% of the time it actually changes as it should when reading its value.
4). I am not able to write anything to the RTCC via I2C using the 610A. The processor gets stuck polling the ACKSTAT bit (I assume because it received a NACK from the RTCC.) The 610 works perfect.
Tools: MPLAB v8.86, C30 v3.31, ICD3
Thank you, Brad
//Write RTCC Register: This functions writes a Byte to the DS1374 RTCC
void Write_RTCC_Register(int Register, unsigned char Byte
{
unsigned int config2, config1;
/* Baud rate is set for 100 Khz */
config2 = 0x97;
/* Configure I2C for 7 bit address mode */
config1 = (I2C1_ON & I2C1_IDLE_CON & I2C1_CLK_HLD &
I2C1_IPMI_DIS & I2C1_7BIT_ADD &
I2C1_SLW_DIS & I2C1_SM_DIS &
I2C1_GCALL_DIS & I2C1_STR_DIS &
I2C1_NACK & I2C1_ACK_DIS & I2C1_RCV_DIS &
I2C1_STOP_DIS & I2C1_RESTART_DIS &
I2C1_START_DIS);
OpenI2C1(config1,config2);
IdleI2C1();
StartI2C1();
//Configure RTCC
//Wait till Start sequence is completed
while(I2C1CONbits.SEN);
//Clear interrupt flag
IFS1bits.MI2C1IF = 0;
//Write Slave address and set master for transmission
MasterWriteI2C1(0xD0);
//Wait till address is transmitted
while(I2C1STATbits.TBF); // 8 clock cycles
while(!IFS1bits.MI2C1IF); // Wait for 9th clock cycle
IFS1bits.MI2C1IF = 0; // Clear interrupt flag
while(I2C1STATbits.ACKSTAT);
OpenI2C1(config1,config2);
IdleI2C1();
StartI2C1();
//Wait till Start sequence is completed
while(I2C1CONbits.SEN);
//Clear interrupt flag
IFS1bits.MI2C1IF = 0;
//Write Slave address and set master for transmission
MasterWriteI2C1(Register);
//Wait till address is transmitted
while(I2C1STATbits.TBF); // 8 clock cycles
while(!IFS1bits.MI2C1IF); // Wait for 9th clock cycle
IFS1bits.MI2C1IF = 0; // Clear interrupt flag
***while(I2C1STATbits.ACKSTAT); //problem here***
//Clear interrupt flag
IFS1bits.MI2C1IF = 0;
//Write Slave address and set master for transmission
MasterWriteI2C1(Byte);
//Wait till address is transmitted
while(I2C1STATbits.TBF); // 8 clock cycles
while(!IFS1bits.MI2C1IF); // Wait for 9th clock cycle
IFS1bits.MI2C1IF = 0; // Clear interrupt flag
while(I2C1STATbits.ACKSTAT);
StopI2C1();
//Wait till stop sequence is completed
while(I2C1CONbits.PEN);
CloseI2C1();
}; //Write RTCC Register