Hi Anton,
thank you very much for your suggestion .. I saw a big mistake on my inmplementation , because one is address of device _dev_address and the other is the address inside the device _addr . I doing this port at 3 am of this night :)
This is my new implementation ... what do you think ?
For readmem ... write is bit simple :)
best
Roberto
void BMP085::writemem(byte _addr, byte _val) {
#ifndef WIRE
uint8 buff[2];
buff[0]=_addr;
buff[1]=_val;
msgs[0].addr = _dev_address;
msgs[0].flags = 0;
msgs[0].length = 2;
msgs[0].data = buff;
i2c_master_xfer(I2C2, msgs, 1);
/*
uint8 buff[1];
buff[0]=_val;
msgs[0].addr = _addr;
msgs[0].flags = 0;
msgs[0].length = 1;
msgs[0].data = buff;
i2c_master_xfer(I2C2, msgs, 1);
*/
#else
Wire.beginTransmission(_dev_address); // start transmission to device
Wire.send(_addr); // send register address
Wire.send(_val); // send value to write
Wire.endTransmission(); // end transmission
#endif
}
void BMP085::readmem(byte _addr, int _nbytes, byte __buff[]) {
#ifndef WIRE
int i;
/* Repeated start condition */
uint8 ibuff[2];
ibuff[0]=_addr;
msgs[0].addr = _dev_address;
msgs[0].flags = 0;
msgs[0].length = 1;
msgs[0].data = ibuff;
i2c_master_xfer(I2C2, msgs, 1);
__buff[0]=_addr;
msgs[0].addr = _dev_address;
msgs[0].flags = 0;
msgs[0].length = 1;
msgs[0].data = 0x0;
msgs[1].addr = _dev_address;
msgs[1].flags = I2C_MSG_READ;
msgs[1].length = _nbytes;
msgs[1].data = __buff;
i2c_master_xfer(I2C2, msgs, 2);
Serial1.print("nbyte:");
Serial1.println(_nbytes);
for (i=0;i<=_nbytes;i++)
{
Serial1.print((int)__buff[i]);
Serial1.print(".");
}
Serial1.println("");
#else
Wire.beginTransmission(_dev_address); // start transmission to device
Wire.send(_addr); // sends register address to read from
Wire.endTransmission(); // end transmission
Wire.beginTransmission(_dev_address); // start transmission to device
Wire.requestFrom(_dev_address, _nbytes);// send data n-bytes read
byte i = 0;
while (Wire.available()) {
__buff[i] = Wire.receive(); // receive DATA
i++;
}
Wire.endTransmission(); // end transmission
#endif
}
Now I try on device :)