I have used LCD module to use as I2C slave
I tried to sending and read sent data
that Pin of I2C work with sending data correctly on p4 p5 p6
but returning from slave have alway 0 on bit 3, bit6
pin state : Out = 11111111 , In= 10110111
This is work correctly?
#include <Wire.h>
void setup()
{
Wire.begin(); // Start I2C bus
Serial.begin(115200); // Setup serial for debug
}
void loop()
{
byte address,data,device;
for(address = 1; address < 127; address++ ) // sets the value (range from 1 to 127)
{
Wire.beginTransmission(address); // transmit to address
if (Wire.endTransmission() == 0) // I2C devices found
{
device = address;
Serial.print("\n I2C Device Address: "); // Print Device Address
Serial.println(address, HEX); // print as an ASCII-encoded hexa);
}
}
byte x;
for (data = 0 ; data <= 255; data++) // sets the value (range from 0 to 255)
{
Wire.beginTransmission(device); // transmit to device
Wire.write(data); // sends one byte
Wire.endTransmission(); // stop transmitting
Serial.print("pin state : Out = "); // Print pin state
Serial.print(data, BIN); // print as an ASCII-encoded binary);
delay(100); // wait for 100 milliseconds
Wire.requestFrom(device, 1); // receive 1 bytes from slave device
x = Wire.read(); // Read pin state
Serial.print("\t, In= "); // Print pin state
Serial.println(x, BIN); // print as an ASCII-encoded binary);
}
}