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