Apologies. I have stripped everything not needed from the script to keep it really simple and confirmed that this exhibits the same issue.
Code for master:
#include <Wire.h>
void setup() {
Wire.begin();
Wire.setClock(400000L);
Serial.begin(115200);//For testing only
}
void loop() {
unsigned long lastMillisSlave=0;
if((unsigned long)(millis()-lastMillisSlave)>=50){
lastMillisSlave=millis();
requestStatusFromSlave();
}
}
void requestStatusFromSlave(){
Serial.println("Requesting status");
Wire.requestFrom(1, 32);
while(Wire.available()){
char c=Wire.read();
Serial.print(c);
}
Serial.println("");
}
And Slave *** this is the one that will give the serial output of the error:
#include <Wire.h>
volatile unsigned long lastUpdateMillis=0;
void setup() {
Wire.begin(1);
Wire.setClock(400000L);
Wire.onRequest(requestStatus);
Serial.begin(115200);//For testing only
}
void loop() {
unsigned long thisNum=millis()-lastUpdateMillis;
if(thisNum>=2000){
Serial.print("thisNum is ");
Serial.println(thisNum);
Serial.print("Millis is ");
Serial.println(millis());
Serial.print("lastUpdateMillis is ");
Serial.println(lastUpdateMillis);
//Turn off all digital IOs
}
}
/* Report status back to Master */
void requestStatus(){
lastUpdateMillis=millis();
for(byte i=0;i<32;i++) Wire.write("A");
}