I2C master/slave code below works perfect between Mega/Uno R4. When swapping Mega with Giga R1 and using TXS0108E based logic level converter, Uno randomly displays correct int from Giga. For the most part, it doesn't receive anything. Wired the logic level chip with Va 3.3 Vb 5V and OE 3.3V. All channels on Va side measure 3.3 and Vb 5V. Any ideas as to why this is happening?
Mega/Giga Master:
#include <Wire.h>
const int TestPB = 11;
byte x = 0;
int Test = 0;
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600);
pinMode(TestPB, INPUT_PULLUP);
}
void loop()
{
Test = digitalRead(TestPB);
if (Test == LOW) {
Wire.beginTransmission(1); //
Wire.write(x);
delay(250); // sends one byte
Wire.endTransmission(); // stop transmitting
x++;
}
delay(250);
Serial.println(x);
delay(250);
}
Uno R4 Wifi Slave:
// Wire Peripheral Receiver
// by Nicholas Zambetti [http://www.zambetti.com](http://www.zambetti.com)
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI Peripheral device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
byte x = 0;
#include <Wire.h>
void setup()
{
Wire.begin(1);
Wire.onReceive(receiveEvent); // join i2c bus with address #4
//Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void receiveEvent(int bytes) {
x = Wire.read(); // read one character from the I2C
}
void loop()
{
Serial.println(x);
}
// function that executes whenever data is received from master