Open
Description
I am using the I2C outputs of an Arduino R4 minima board to make it communicate with other boards. I notice that the Wire.end()
function does not seem to work. I commonly use this instruction to alternately switch the Uno R4 board to a "master" controller and a "slave" controller. Is this an error on my part?
Below is the sketch I am using for my tests.
"master" controller
/* Test de fonctionnement du bus I2C
Test d'envoi en controleur maitre de la carte
uno R4.*/
#include <Wire.h>
void setup() {
while (!Serial && millis() < 4000);
Serial.println("Demarrage");
Wire.begin(50);
}
void loop() {
Wire.end();
Wire.begin();
Serial.println("Envoi d'un texte");
Wire.beginTransmission(52);
Wire.write("Test d'envoi en maitre");
Wire.endTransmission();
Wire.end();
Wire.begin(50);
/*Serial.println("Demande 6 caractères");
Wire.requestFrom(52, 6); // request 6 bytes from peripheral device #8
while (Wire.available()) { // peripheral may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}*/
delay(10000);
}
"slave" controller
/* Test de fonctionnement du bus I2C
Test de réception en controleur esclave de la carte
Arduino Nano-Every.*/
#include <Wire.h>
void setup() {
Serial.begin(115200);
Serial.println("Demarrage");
Wire.begin(52);
Wire.onReceive(receiveEvent);
Wire.onRequest(requestEvent);
}
void loop() {
delay(100);
}
void receiveEvent(int howMany) {
Serial.print("Nombre d'octets : "); Serial.println(howMany);
while(Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
Serial.println();
}
void requestEvent() {
Wire.write("hello "); // respond with message of 6 bytes
}
Metadata
Metadata
Assignees
Labels
No labels