File tree 2 files changed +10
-4
lines changed
master_reader_custombuffer
slave_receiver_custombuffer
2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ void loop() {
34
34
Wire.requestFrom (8 , REQUESTED_BYTE_COUNT);
35
35
36
36
while (Wire.available ()) { // slave may send less than requested
37
- char c = Wire.read (); // receive a byte as character
37
+ char c = Wire.read (); // receive a byte as character
38
38
Serial.print (c); // print the character
39
39
}
40
40
Serial.println ();
Original file line number Diff line number Diff line change @@ -34,12 +34,17 @@ void loop() {
34
34
35
35
// function that executes whenever data is received from master
36
36
// this function is registered as an event, see setup()
37
+ //
38
+ // Hint: This function is called within an interrupt context.
39
+ // That means, that there must be enough space in the Serial output
40
+ // buffer for the characters to be printed. Otherwise the
41
+ // Serial.print() call will lock up.
37
42
void receiveEvent (int howMany) {
38
43
while (1 < Wire.available ()) { // loop through all but the last
39
- const char c = Wire.read (); // receive byte as a character
40
- Serial.print (c); // print the character
44
+ const char c = Wire.read (); // receive byte as a character
45
+ Serial.print (c); // print the character
41
46
}
42
- const int x = Wire.read (); // receive byte as an integer
47
+ const int x = Wire.read (); // receive byte as an integer
43
48
Serial.println (x); // print the integer
44
49
}
45
50
@@ -60,4 +65,5 @@ void printWireBuffersCapacity(Stream& stream) {
60
65
61
66
stream.print (" twi_txBuffer size is " );
62
67
stream.println (buffers.twi_txBufferCapacity ());
68
+ delay (250 ); // Give time to free up Serial output buffer.
63
69
}
You can’t perform that action at this time.
0 commit comments