Created
February 18, 2015 15:38
-
-
Save rwaldron/616e95b7c2637ebd21c5 to your computer and use it in GitHub Desktop.
I2C slave: Wire.write() sending only one byte?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
byte i2cdata[4]; | |
void setup() { | |
Wire.begin(); | |
Serial.begin(9600); | |
} | |
void loop() { | |
Wire.requestFrom(4, 4); | |
int a = Wire.available(); | |
Serial.print("Available: "); | |
Serial.println(a); | |
// Both of these produce the same result | |
// for (int i = 0; i < a; i++) { | |
// Serial.print(Wire.read()); | |
// Serial.print(" "); | |
// } | |
while (Wire.available()) { | |
Serial.print(Wire.read()); | |
Serial.print(" "); | |
} | |
Serial.println(); | |
memset(&i2cdata, 0, 4); | |
delay(500); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
int address = 4; | |
void setup() { | |
Wire.begin(address); | |
Wire.onRequest(onRequest); | |
} | |
void loop() {} | |
void onRequest() { | |
byte buffer[4] = {1, 2, 3, 4}; | |
Wire.write(buffer, 4); | |
} | |
/* | |
When this sketch is running on the slave, the output of the master is: | |
Available: 4 | |
1 2 3 4 | |
... | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
int address = 4; | |
void setup() { | |
Wire.begin(address); | |
Wire.onRequest(onRequest); | |
} | |
void loop() {} | |
void onRequest() { | |
for (int i = 1; i < 5; i++) { | |
Wire.write(i); | |
} | |
} | |
/* | |
When this sketch is running on the slave, the output of the master is: | |
Available: 4 | |
4 255 255 255 | |
... | |
*/ |
Sounds like TinyWireS probably needs an update to bring things in line with this behaviour. I noticed there were a lot of branches doing different things so there's been a lot of fragmentation.
@ajfisher have you tried this I2C library that Adafruit made for the Trinket? https://github.com/adafruit/TinyWireM
actually it looks like TinyWireM only implements I2C master
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the details :)