arduino / arduino/ArduinoCore-renesas

`Wire.end()` function does not seem to work

Open
#382 1 comment 0 reactions 0 assignees View on GitHub
topic: code type: imperfection
Dominant language
C
Stars
193
Forks
112
PR merge metrics
No merged PRs in 30d

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

```cpp
/* Test de fonctionnement du bus I2C
Test d'envoi en controleur maitre de la carte
uno R4.*/

#include

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

```cpp
/* Test de fonctionnement du bus I2C
Test de réception en controleur esclave de la carte
Arduino Nano-Every.*/

#include

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
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the supplied master and slave sketches and trace the Wire.end() and Wire.begin() calls in the alternating-role sequence. Reproduce the reported behavior on the Uno R4 Minima and Nano Every, then confirm that the I2C controller can switch roles and communicate reliably after reinitialization.

Written by the indexing model from the issue text.

Assessment

Tech stack
arduino, cpp
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.