Hi All,
Got a big issue trying to transfer data between a ATmega328p using Arduino core/wire and a ATtiny44 (and same issue on ATtiny85) using the tiny core/TinyWire.
The issue is in TinyWireM I request 3 bytes from the 328, I successfully receive the request, and respond with 3 bytes, however TinyWireM only receives the first byte. I ran into the issue when working on a project, but created stripped down code, and still have the issue.
On the master I have:
#include <Wire.h>
void setup()
{
Wire.begin(0x9);
Wire.onReceive(receiveEvent);
Wire.onRequest(requestEvent);
Serial.begin(9600);
}
void loop() {
}
void receiveEvent(int sizeIn) {
Serial.println("receive");
byte a = Wire.read();
byte b = Wire.read();
byte c = Wire.read();
Serial.println(a,DEC);
Serial.println(b,DEC);
Serial.println(c,DEC);
}
void requestEvent() {
Serial.println("request");
byte outa = 0x10;
byte outb = 0x20;
byte outc = 0x30;
Serial.println(outa);
Serial.println(outb);
Serial.println(outc);
Wire.write(outc);
Wire.write(outb);
Wire.write(outa);
}
On the slave I have:
#include <TinyWireM.h>
#define THIS_ADDRESS 0x8
#define OTHER_ADDRESS 0x9
void setup() {
int wireRet = 0;
TinyWireM.begin();
//Serial.begin(9600);
delay(1000);
wireRet = TinyWireM.requestFrom(OTHER_ADDRESS, 3);
if (wireRet) {
Serial.println("RcveError: ");
Serial.println(wireRet,DEC);
}
//while(TinyWireM.available()){
//Serial.println(TinyWireM.available(),DEC);
//while(TinyWireM.available() < 3){}
byte a = TinyWireM.receive();
byte b = TinyWireM.receive();
byte c = TinyWireM.receive();
//Serial.println(a,DEC);
//Serial.println(b,DEC);
//Serial.println(c,DEC);
TinyWireM.beginTransmission(OTHER_ADDRESS);
TinyWireM.send(a);
TinyWireM.send(b);
TinyWireM.send(c);
TinyWireM.endTransmission();
}
void loop() {
}
available() reports 3 bytes are waiting (but maybe only because I requested 3), then first byte is read successfully, but the other two return 255 in decimal
I’ve had it printing the results by serial on the ATtiny, and sending them back via i2c etc, but the results are the same.
Here is the serial output from the ATmega328:
request
16
32
48
receive
16
255
255
Can anybody help as to why this isn’t working?
BONUS QUESTION: I’m having to do it this way (328 will flag an interrupt pin on an array of ATtiny’s, who will then request data from the 328 as to what it needs to do (recalibrate etc). The ATtiny’s will also send messages to the 328, so its acting as both master and slave) because I cant get TinyWireM and TinyWireS working together to act as both a slave and master, otherwise the 328 could just send commands to the ATtiny’s, and the ATtiny’s send data back as needed.
It would be great if anyone was able to help get both TinyWireM and TinyWireS working together?
Regards