Other Parts Discussed in Thread: MSP430FR2422
Tool/software:
**Subject:** PCF8574 I2C NACK Issue with MSP430FR2422
**Problem Statement:**
I am interfacing the PCF8574 with MSP430FR2422 using a bit-banging I2C implementation. Despite correct start/stop conditions and data transitions (verified on an oscilloscope), the PCF8574 always responds with a NACK after the address byte (`0x40` for write).
1. **PCF8574 Address:** A0, A1, A2 are grounded (address: `0x40`).
**Code:**
```
void init_I2C(void)
{
CONF_SCL_OP;
CONF_SDA_OP;
}
void I2C_Start_Bit(void)
{
SET_SDA; I2C_Delay();
SET_SCL; I2C_Delay();
RST_SDA; I2C_Delay();
RST_SCL;
}
void I2C_Stop_Bit(void)
{
RST_SCL; I2C_Delay();
RST_SDA; I2C_Delay();
SET_SCL; I2C_Delay();
SET_SDA;
}
unsigned char I2C_Get_Ack(void)
{
unsigned char ack;
RST_SDA;
RST_SCL;
SET_SDA;
CONF_SDA_IP; I2C_Delay();
SET_SCL; I2C_Delay();
//I2C_Delay();
if(!GET_SDA_LVL)
ack = 1;
else
ack = 0;
RST_SCL;
CONF_SDA_OP;
return(ack);
}
void DataSendToI2C(unsigned char rdata)
{
unsigned char i;
CallNop();//asm("NOP");
for(i=0;i<8;i++)
{
if(rdata & 0x80)
SET_SDA;
else
RST_SDA;
I2C_Delay();
SET_SCL; I2C_Delay();
RST_SCL; I2C_Delay();
rdata = rdata<<1;
}
I2C_Delay();
i= I2C_Get_Ack();
I2C_Delay();
CallNop();//asm("NOP");
}
unsigned char DataRecvFromI2C(void)
{
unsigned int i,recd;
recd = 0;
SET_SDA;
P1REN|=BIT5;
CONF_SDA_IP;
I2C_Delay();
for(i=0;i<8;i++)
{
recd = recd<<1;
SET_SCL;
I2C_Delay();
if(GET_SDA_LVL)
recd = recd|0X01;
RST_SCL;
I2C_Delay();
}
P1REN&=~BIT5;
CONF_SDA_OP;
return(recd);
}
void I2C_Delay(void)
{
unsigned char Del=100;//50
while (Del--);
}
void CallNop(void)
{
asm("NOP:");
}
void I2CDev_Delay(void)
{
unsigned char Del=100;//50
while (Del--);
}
void ReadWriteDelay(void)
{
unsigned int Del=4000;
while (Del--);
}
void PCF8574_Write(unsigned char DeviceAdd, unsigned int data)
{
I2C_Start_Bit();
I2CDev_Delay();
DataSendToI2C(DeviceAdd);
I2CDev_Delay();
cnt=0;
DataSendToI2C(data);
I2CDev_Delay();
I2C_Stop_Bit();
CallNop();
ReadWriteDelay();
}
void main(void)
{
init_I2C();
while (1) {
PCF8574_Write(0x40,0x00);
Delay_3ms(1);
}
}
``
**Question:**
Why is the PCF8574 always responding with a NACK after the address byte, and how can this be resolved?