This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Communication with apple coprocessor over I2C

Other Parts Discussed in Thread: MSP430F5438A

Dear All,

I am working with MSP430F5438A microcontroller and apple authentication co-processor V2.0C. I have followed all hardware requirements mentioned in documentation provided by apple. I am using following code for initializing I2C (my CPU frequency is 20MHz)

void halI2CB3Init(void)
{
  unsigned short timeout = 20000;
  unsigned char temploop=0;

  UCB3SDA_SEL |= UCB3SDA_PIN;
  UCB3SCL_SEL |= UCB3SCL_PIN;
  //DIR Registers are don't cares
  UCB3SDA_DIR |= UCB3SDA_PIN;
  UCB3SCL_DIR |= UCB3SCL_PIN;

  UCB3CTL1 |= UCSWRST;                      // Enable SW reset
  UCB3CTL0 = UCMST + UCMODE_3 + UCSYNC;     // I2C Master, synchronous mode
  UCB3CTL1 = UCSSEL_2 + UCSWRST;            // Use SMCLK
  UCB3BR0 = 200;//50;//62;//45;                             // fSCL = SMCLK/45 = ~400kHz
  UCB3BR1 = 0;
  UCB3CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation

  //Generate STOP condition at least 9 times to make sure that the slave will release the bus at MCU power up.
  for(temploop=9;temploop>0;temploop--)
  {
    UCB3SDA_OUT &= ~UCB3SDA_PIN;            // SCL 0
    UCB3SCL_OUT &= ~UCB3SCL_PIN;            // SDA 0
    UCB3SDA_OUT |= UCB3SDA_PIN;             // SCL 1
    UCB3SCL_OUT |= UCB3SCL_PIN;             // SDA 1
  }


  UCB3SDA_OUT |= UCB3SDA_PIN;
  UCB3SCL_OUT |= UCB3SCL_PIN;
  AUTH_RST_OUT |= AUTH_RST_PIN;
  AUTH_RST_OUT &= ~AUTH_RST_PIN;
  __delay_cycles((unsigned long) 18 * 15);
  AUTH_RST_OUT |= AUTH_RST_PIN;

  while((UCB3STAT & UCBBUSY) && (--timeout > 0)); //PRC 15MAY - added

}

But I am not getting ACK from apple co-processor when I write slave address, for doing so I am using following code-

unsigned char halI2CB3SendSlaveAddress(enum halI2Copt read)
{
  unsigned char brkflag=1, lap=0;
  unsigned short timeout = 20000;

  while(brkflag)
  {
    // Ready the 7bit address
    UCB3I2CSA = auth_i2c_address;
    UCB3CTL0 &= ~UCSLA10;
    // Transmit flag
   
      UCB3CTL1 |=  UCTR;
    // Send Start Condition
    UCB3CTL1 |= UCTXSTT;
    {
      // Wait for ACK or NACK after Slave Address
      while ((UCB3CTL1 & UCTXSTT) && (--timeout > 0));
      if(UCB3IFG & UCNACKIFG)
      {
        __delay_cycles((unsigned long) 18 * 600); //600 usec delay
//        __delay_cycles((unsigned long) 18 * 5000); //PRC 5SEP12 - 5000 usec delay //Not working.

        timeout=20000;
        ++lap;
        if(temp_lap < lap)
        {
          DEBUG_PRINTF(DEBUG_CP,"T:S2:%d~",lap);
          return 2;// return failure since ACK not received.
        }
      }
      else
        brkflag=0;
    }
  }
  return 0;// Ack received
}

Can anyone help me with what went wrong here?

My function always returns 2 here.

Thanks in advance,

Sharadanand Karanjkar

  • Hi Sharadanand,

    Have you monitored the bus using a scope? Can you see the msp430 generating the address as required by the co-processor? It isn't uncommon to get confused with the 7bit i2c address. (the 8th bit is for read/write status). 

    Secondly, does the bus look correct? i.e. do both lines start at high voltage etc. What are your pullup resistor values? 

    I haven't seen the datasheet - but make sure it can support 400kHz (the default is normally 100kHz or less). Verify this with the scope.

    If your code generates the right signals on the bus then you need to check the co-processor - or your understanding of the address or its modes (is it listening to i2c). If your code doesn't, then maybe look at the example code folder for the msp430.

    Hope this helps you get on your way, 

**Attention** This is a public forum