Wire library ignoring delay in code for I2C

So I am working on a project where I communicate to a IR temp sensor over I2C from an Arduino Uno. I am using the arduino Wire library to do the communication, I want it to request the temperature data once a second so I added a 1000ms delay in the void loop(). However, despite the delay function in there the arduino is sending the request every 2.5ms. I have attached the code and screen shot of the logic analyzer, any insight would be great.

#include <Wire.h>

void setup() {
  // put your setup code here, to run once:
  Wire.begin();
  
  #if defined(WIRE_HAS_TIMEOUT)
    Wire.setWireTimeout(3000 /* us */, true /*reset on timeout */);
  #endif

  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  Wire.beginTransmission(0x5A);
  Wire.write(0x07);
  Wire.requestFrom(0x5A, 3, true);
  while (Wire.available()){
    byte c = Wire.read();
    Serial.print(c, HEX);
    Serial.print(" / "); 
  }
  Wire.endTransmission();
  Serial.println();
  delay(1000);
  
}

Maybe you are not waiting long enough between the requestFrom send and the while() loop.
Could be it isn't receiving anything yet when it gets to the while loop.

Why did you set the Wire timeout, and why aren't you checking whether the timeout return is true?

Alright figured it out and it was 100% user error. I'm prototyping for a different micro with the arduino and there were on the same i2c line acting as masters. I thought the other micro had the i2c code commented out and it did not. Sometimes my genius amazes lmao

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.