Running a test on a PIC16F18877 I encounter a problem with i2cWrite.
During sending an adress to a TCA9555 i can not get a proper ACK. After I2c start the function is called with slave adress 0x40. In fact 0x20 first 7 bits for slave adress complemented with 0 for Write on bit 0. A0;A1 and A2 are all pulled to GND. Testing with a different TCA9555 gives the same error.
I need to see ACK becomes 0 but the return value is 1.
The i2cWritefunction has been used in many projects and tested just now with a DS3231. From this device I get a proper ACK.
Stepping through the function shows the proper SDA high and low signals. Even visible on the SDA line itself.
I might be doing something wrong with the TCA9555 but have no idea what.
bit i2cWrite(const unsigned char Byte)
{
unsigned char i = 0;
for(i=0;i<8;i++) // Repeat for every bit
{
Set_SCL_Low;
Delay();
// when it is confirm that SCL is low
if((Byte<<i)&0x80) // Place data bit value on SDA pin
Set_SDA_High; // If bit is high, make SDA high
else // Data is transferred MSB first
Set_SDA_Low; // If bit is low, make SDA low
Delay();
Set_SCL_High; // So that slave can ackknowldege
Delay();
Delay();
}
// Get ACK from slave
Set_SCL_Low;
Set_SDA_High;
Delay();
Delay();
Set_SCL_High;
Delay();
Delay();
return SDA;
}