title: I2C Read/Write Issue with RTCC caused by PIC24HJ256GP610/610A Differences?
body: <p>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.</p>
  
  <p>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?</p>
  
  <p>A few things I've noticed when experimenting, probing the signals, and stepping through with the debugger:</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Tools: MPLAB v8.86, C30 v3.31, ICD3</p>
  
  <p>Thank you,
  Brad</p>
  
  <pre><code>//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 &amp; I2C1_IDLE_CON &amp; I2C1_CLK_HLD &amp;
              I2C1_IPMI_DIS &amp; I2C1_7BIT_ADD &amp;
              I2C1_SLW_DIS &amp; I2C1_SM_DIS &amp;
              I2C1_GCALL_DIS &amp; I2C1_STR_DIS &amp;
              I2C1_NACK &amp; I2C1_ACK_DIS &amp; I2C1_RCV_DIS &amp;
              I2C1_STOP_DIS &amp; I2C1_RESTART_DIS &amp;
              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
  </code></pre>