The code below is the PCF8575 library Wire2 test using the Arduino UNO R4 WIFI. It works the first time I upload the code, but on subsequent uploads it fails to connect. To recover, it needs to have the USB-C connect unplugged and plugged in again. Then it works the first time again.
I modified the code to use Wire1 because that is what the Quiic connector uses.
Is this something in the code, the Wire library or the R4?
PCF8575_Wire1.ino
//
// FILE: PCF8575_Wire1.ino
// AUTHOR: Rob Tillaart
// DATE: 2021-01-03
// PUPROSE: demo
#include "PCF8575.h"
// adjust addresses if needed
PCF8575 PCF(0x21, &Wire1);
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PCF8575_LIB_VERSION:\t");
Serial.println(PCF8575_LIB_VERSION);
if (!PCF.begin())
{
Serial.println("could not initialize...");
}
if (!PCF.isConnected())
{
Serial.println("=> not connected");
while(1);
}
int x = PCF.read16();
Serial.print("Read ");
Serial.println(x, HEX);
delay(1000);
}
void loop()
{
Serial.println("HLT");
while (Serial.available() == 0);
switch (Serial.read())
{
case 'H': doHigh(); break;
case 'L': doLow(); break;
case 'T': doToggle(); break;
}
}
void doHigh()
{
PCF.write(4, HIGH);
int x = PCF.read16();
Serial.print("Read ");
Serial.println(x, HEX);
}
void doLow()
{
PCF.write(4, LOW);
int x = PCF.read16();
Serial.print("Read ");
Serial.println(x, HEX);
}
void doToggle()
{
PCF.toggle(4);
int x = PCF.read16();
Serial.print("Read ");
Serial.println(x, HEX);
}