Peripheral Receiver example sketch Makes the board an I2C peripheral at address 0x42. Prints the bytes a controller writes, and answers each read with a counter that goes up by one.
Uses PhyduinoWire::begin(uint8_t) with PhyduinoWire::onReceive() and PhyduinoWire::onRequest().
- Wiring
- SDA, SCL and GND to another board running a controller sketch.
- Output
- Serial Monitor at 115200 baud: the bytes the controller wrote, as text.
- Note
- The callbacks run inside the I2C interrupt, so keep them short.
volatile uint8_t counter = 0;
void onReceive(int count) {
(void)count;
while (
Wire.available()) {
}
}
void onRequest() {
}
Wire.onReceive(onReceive);
Wire.onRequest(onRequest);
}
SerialUSBClass Serial
USB serial port, the one the Serial Monitor uses.
Arduino Wire (I2C) on the SDA/SCL header pins.
PhyduinoWire Wire
I2C on the header SDA / SCL pins.
void loop(void)
Written by the sketch: runs over and over after setup(), on core 0.
void setup(void)
Written by the sketch: runs once after reset, on core 0.