Thak you for your replies Jason and Robert,
At the code below, i tried to read the data from Arduino UNO. However, The UNO use Wire library and i think it does not works as i thought. The whole data i get from the i2c bus is meaningless.
void ReadData()
{
cliSerial->printf_P(PSTR("Reading.."));
cliSerial->println();
hal.scheduler->delay(500);
AP_HAL::Semaphore* i2c_sem = hal.i2c->get_semaphore();
if(!i2c_sem->take(200))
return;
hal.i2c->read(SLAVE_ADDRESS, 1, &readData);
i2c_sem->give();
cliSerial->printf_P(PSTR("Read: %d"), (int)readData);
//cliSerial->printf_P(readData);
cliSerial->println();
}
The all thing i understand from the example of Master_Reader and Slave_Sender of the Wire library is that master interrupts the slave for requesting data by (requestFrom function) and slave sends the data to the i2c bus after it recognizes the interrupt.
Master Side:
Wire.requestFrom(2, 6); // request 6 bytes from slave device #2
while(Wire.available()) // slave may send less than requested
{
char c = Wire.read(); // receive a byte as character
}
Slave side:
void setup()
{
Wire.begin(2); // join i2c bus with address #2
Wire.onRequest(requestEvent); // register event
}
void requestEvent()
{
Wire.write("hello "); // respond with message of 6 bytes
// as expected by master
}
And im not sure i can achieve reading data from the UNO by using the I2CDriver. Or there is another approach?
Yours sincerely..
Fahrettin