Hi there,
I've realized a sensor device and trying to send three bytes.
I goes well e.g. by sending data like 0x7F 0x45 0x10 and data are received from the master device properly.
However as soon as my databyte (which shall be transmitted) exceed 0x7F, only 0xFF will be received.
This shouldn't be the proper behaviour????
Example code, which increases the first transmission byte every time data is requested (all fine unless byte[0] steps above 0x7F)
#define SLAVE_ADDRESS 50 //50 0x64
const long BAUDRATE = 38400;
#include <Wire.h>
// Data to be received from the master
byte receivedData = 0;
byte myData=0;
void setup()
{
// Start the I2C communication as a master
Wire.begin();
// Start the I2C communication as a slave with the given address
Wire.begin(SLAVE_ADDRESS);
// Register a callback function to be called when data is received from the slave
Wire.onRequest(requestEvent); // register event
}
void loop()
{
}
void requestEvent() {
byte buffer[10];
buffer[0] = (myData+=10);
buffer[1] = 10; // 0x0A
Serial.println("I2C Request ");
Serial.print(buffer[0]);
Serial.print("\t");
Serial.print(buffer[1]);
// as expected by master
Wire.write( buffer[0]);
Wire.write( buffer[1]);
Wire.write('c');
}
I'm using a I²C sniffer and confirms the behaviour!
What am I doing wrong?