// Stress test for SoftwareWire library. // Tested with an Arduino Uno connected to an Arduino Uno. // This is the sketch for the Slave Arduino using the hardware I2C. #include volatile byte buffer[40]; volatile int rxHowMany; volatile int rxInterrupts = 0; volatile boolean flagRequest; void setup() { Serial.begin(9600); // start serial for output Serial.println("\nSlave"); Wire.begin(4); // join i2c bus as slave with address #4 Wire.onReceive(receiveEvent); // interrupt handler for receiving i2c data Wire.onRequest(requestEvent); // interrupt handler for when data is requested by i2c } void loop() { noInterrupts(); int rxInterruptsCopy = rxInterrupts; rxInterrupts = 0; interrupts(); // Using all the text output to the Serial port is part of the stress test. // That causes delays and interrupts. if( rxInterruptsCopy > 0) { Serial.print("Receive: "); if( rxInterruptsCopy > 1) { // Printing to the serial port at 9600 is slow. // Therefor it is normal that this sketch misses received data, // if too much data was received. // As long as the i2c data is correct, everything is okay. It is a stress test. Serial.print("Missed:"); Serial.print( rxInterruptsCopy); Serial.print(" "); } Serial.print("howMany:"); Serial.print( rxHowMany); Serial.print(", data:"); for(int i=0; i