Hi,
I'm using an MSP430F5438 connected with I2C to a Maxim DS2482-800, where the MSP430 is the I2C Master device and the DS2482-800 is the I2C Slave device.
The communication protocol needs that the I2C Master (MSP430) issues the following sequence of I2C operations:
[M - S] Start Tx
[M - S] Address
[S - M] Ack
[M - S] 1WRB
[S - M] Ack
[M - S] Repeated Start Rx
[M - S] Address
[S - M] Ack
[S - M] byte
[M - S] Ack
[S - M] byte
[M - S] Nack
[M - S] Repeated Start Tx
[M - S] Address
[S - M] Ack
[M - S] SRP
[S - M] Ack
[M - S] E1h
[S - M] Ack
[M - S] Repeated Start Rx
[M - S] Address
[S - M] Ack
[S - M] byte
[M - S] Nack
[M - S] Stop
My problem appears when the MSP430 (Master Receiver) needs to send the NACK (bold yellow line).
The function I'm using is the following:
unsigned char I2C_read(int mode)
{
unsigned char b;
if(mode == I2C_READ_AND_NAK)
{
UCB0CTL1 |= UCTXNACK; // I2C nak
while(!(UCB0IFG & UCRXIFG)); // Wait for RX data
b = UCB0RXBUF;
while(UCB0CTL1 & UCTXNACK);
}
else if (mode == I2C_READ_AND_STOP)
{
UCB0CTL1 |= UCTXSTP; // I2C stop condition
while(!(UCB0IFG & UCRXIFG)); // Wait for RX data
b = UCB0RXBUF;
}
else
{
while(!(UCB0IFG & UCRXIFG)); // Wait for RX data
b = UCB0RXBUF;
}
return b;
}
My code hangs on the green line and never goes out, and I'm not understanding why the MSP430 (I2C Master Receiver) can't send out the NAK.
Thanks for any help and suggestions.
Regards,
Samuele.