I am using an Arduino Uno R3 as an i2c Slave. From my master, I am writing a bit value for storage purposes to update the value on an LCD. If I write to another device on the I2C line, the write is effective. However, on the Arduino itself, it sees the value sent but does not update the register.
I can successfully connect to the I2C slave from my master and can read any register but it spits the default FF. I want to change the value of a register say 0x00.
I am verifying the written statement is unsuccessful from my master with a read of the register in question. I am simply trying to store a value that is read from the master and use that same value in another part of a different program.
// Include the required Wire library for I2C<br>
#include <Wire.h>
int LED = 13;
int x = 0;
void setup()
{
Wire.begin(9); // join i2c bus with address #9
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
Wire.setClock(100000);
}
void loop()
{
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
// Wire.write());
}
What do I need to add to the above code to declare a register and allow writes to it?