johnnyfp
Well-known member
Hi,
I've got a very simple Master slave setup where the T3.6 would ignore any packets not addressed to it (as it should) and would fire the onRequest callback when a packet is addressed to it.
However after the first addressed message, the T3.6 would then fire the onRequest callback for any packets on the I2C bus regardless of the address used.
This is the code I used on the T3.6. I have tried this on all 4 Wire channels on the T3.6 with the same effect (I have enabled the Wire3 in the library).
Then on the master all I'm doing is the following.
and the console would output
Any ideas why this is happening?
I've got a very simple Master slave setup where the T3.6 would ignore any packets not addressed to it (as it should) and would fire the onRequest callback when a packet is addressed to it.
However after the first addressed message, the T3.6 would then fire the onRequest callback for any packets on the I2C bus regardless of the address used.
This is the code I used on the T3.6. I have tried this on all 4 Wire channels on the T3.6 with the same effect (I have enabled the Wire3 in the library).
Code:
#include <Wire.h>
uint32_t timeNow=0;
uint32_t tickTime=0;
boolean ledDone=false;
int indistate=0;
uint8_t opcode3=0;
bool wire3Received=false;
bool wire3Requested=false;
void wire3ReceiveHandlerFunction(int bytesReceived){
wire3Received=true;
while(1<Wire3.available()) Wire3.read();
opcode3 = Wire3.read();
}
void printReceived(int port,int code){
Serial.printf("SDA%d received 0x%02x\r\n",port,code);
}
void wire3RequestHandlerFunction(){
wire3Requested=true;
Wire3.write(1);
Wire3.write(3);
Wire3.write(3);
opcode3=0;
}
void printRequest(int port) {
Serial.printf("SDA%d Request called\r\n",port);
}
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN,OUTPUT);
Wire3.begin(0x6D);
Wire3.onReceive(wire3ReceiveHandlerFunction);
Wire3.onRequest(wire3RequestHandlerFunction);
timeNow=millis();
}
void loop() {
if (wire3Received) {
printReceived(3,opcode3);
wire3Received=false;
}
if (wire3Requested) {
printRequest(3);
wire3Requested=false;
}
if (millis()-timeNow>250) {
tickTime++;
timeNow=millis();
}
if (tickTime%2==1) {
if (!ledDone) {
digitalWrite(LED_BUILTIN,HIGH);
ledDone=true;
}
} else {
if (ledDone) {
digitalWrite(LED_BUILTIN,LOW);
ledDone=false;
}
}
}
Then on the master all I'm doing is the following.
Code:
Wire.begin();
Wire.beginTransmission(0x6D);
Wire.write(0x77);
Wire.endTransmission();
Wire.requestFrom(0x6D,3);
Wire.read();
Wire.read();
Wire.read();
delay(1000);
Wire.beginTransmission(0x50);
Wire.write(0x50);
Wire.write(0x18);
Wire.endTransmission();
Wire.requestFrom(0x50,4);
Wire.read();
Wire.read();
Wire.read();
Wire.read();
and the console would output
Code:
SDA3 received 0x77
SDA3 Request called
SDA3 received 0x77 <--Not expected
SDA3 received 0x77 <--Not expected and appeared when the Wire request to Addr 0x50 was called.
Any ideas why this is happening?