0

I want to know why Wire.onRequest can not detect below massage and what I can do to detect it.(I am not able to change I2C massage)

I was able to read this part of the massage with wire.onReceive:

enter image description here

But I can not read this massage at all, which is requesting: enter image description here

#include <Wire.h>
byte val = 170;
int sendv;

char c;

byte dataArray[16];

void setup() {
  Wire.begin(0x77);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Wire.onRequest(requestEvent); // register event
  Serial.begin(9600);           // start serial for output
}

void loop() { }

void receiveEvent(int howMany) {
  Serial.println(howMany);

  if (howMany >= 2) {
    for (int i = 0 ; i < howMany; i++) {
      dataArray[i] =  Wire.read();
      Serial.println(dataArray[i], HEX);
    }

  } else {
    c =  Wire.read();
    Serial.println(c, HEX);
  }
}

void requestEvent() {
  Serial.println("REqEVENT");
}
  • So you mean in your code you are never seeing the REqEVENT in the serial monitor? Normally in the onRequest callback you would write data to the I2C buffer, so that it can be send – chrisl Sep 26 '19 at 15:59
  • Yes, when I run the code I never goes inside of request event and I dont see REqEVENT, which it should becouse 0xEFm or 0xEE is correct address – Shahreza Sep 26 '19 at 16:00
  • Are the images from the transmission from your code? That would fit your code, since you don't send any data on request. Maybe sending over serial is not a good test here, since the function get's called from an ISR. Try to light an LED inside the function to test, if the code get's there. Also try to actually send data and see, if this data get's actually send, by watching your logic analyser. – chrisl Sep 26 '19 at 16:03
  • I have tried sending massage which did not work, I just tried Led too and not turning on, Also you can see on logic analyzer is getting 0xFF – Shahreza Sep 26 '19 at 16:09
1

I was able to solve the issue with by adding twi_stop(); to twi.c

base on this website enter link description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.