-
Notifications
You must be signed in to change notification settings - Fork 121
Surprise, as of f0eb04f the communication doesn't work anymore, only 255 response #44
Copy link
Copy link
Open
Description
Surprise, as of f0eb04f the communication doesn't work anymore.
Master (Arduino Micro):
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
}
void loop() {
Wire.requestFrom(10, 4); // request 4 bytes
while (Wire.available()) {
uint8_t c = Wire.read();
Serial.print(c, HEX);
}
Serial.println();
delay(500);
}
Slave ATtiny85
#include <TinyWireS.h>
byte own_address = 10;
volatile uint8_t i2c_regs[] =
{
0xDE,
0xAD,
0xBE,
0xEF,
};
volatile byte reg_position = 0;
const byte reg_size = sizeof(i2c_regs);
void setup() {
TinyWireS.begin( own_address );
TinyWireS.onRequest( onI2CRequest );
TinyWireS.onReceive( onI2CReceive );
}
void loop() {
}
void onI2CRequest() {
TinyWireS.send(i2c_regs[reg_position]);
reg_position++;
if (reg_position >= reg_size)
{
reg_position = 0;
}
}
void onI2CReceive(uint8_t howMany) {
if (howMany < 1)
{
return;
}
if (howMany > reg_size+1)
{
return;
}
reg_position = TinyWireS.receive();
howMany--;
if (!howMany)
{
return;
}
while(howMany--)
{
i2c_regs[reg_position] = TinyWireS.receive();
reg_position++;
if (reg_position >= reg_size)
{
reg_position = 0;
}
}
}
Output with most recent commit (returns always 255 aka "nothing"):

Output with f0eb04f (returns first byte correctly, the remaining bytes are wrong):

See also https://arduino.stackexchange.com/questions/48625/always-255-response-in-i2c-between-attiny85-8mhz-and-arduino-uno and https://forum.pjrc.com/threads/48887-HELP-Teensy-3-5-I2C-ATTiny85-20PU-(TinyWireS-OnRequest-not-triggering!)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels