This is my first time having to write my own I2C code. I recently designed a board for usage with KELLER OEM Pressure Transmitter Sensor. They describe how to do that as below in the datasheet.
https://download.keller-druck.com/api/download/VeMYAQBxgoSNjUSHbdnBTU/en/2017-10.pdf
So I am trying to simulate that as below:
uint64_t OEMPT::read_64bit()
{
uint64_t data = 0;
int i = 4;
Wire.beginTransmission(ADDR<<1);
Wire.write(0xAC);
Wire.endTransmission();
Wire.requestFrom((ADDR<<1)+1, 5);
while(Wire.available())
{
data = (data | (Wire.read())<<(i*8));
i--;
}
return data;
}
What I am trying to is this :
In the beggining the variable "data" is basically blank. I shift the incoming data each time Wire.read() is called, and deacrease the amount it is shifted each time. So at first it is shifted 4bytes at the end it isnt shifted at all.
I took this Adafruit code as reference.
/**************************************************************************/
/*!
@brief Reads two bytes from the specified register
@param reg The address of the register to read from
@return The two bytes read from the sensor starting at the given address
*/
/**************************************************************************/
int16_t Adafruit_ADXL345_Unified::read16(uint8_t reg) {
if (_i2c) {
Wire.beginTransmission((uint8_t)_i2caddr);
i2cwrite(reg);
Wire.endTransmission();
Wire.requestFrom((uint8_t)_i2caddr, 2);
return (uint16_t)(i2cread() | (i2cread() << 8));
}
I dont really know wether my code will work or not and I cant test it right away in the moment as I am working from home. Is there a common method to do what I am trying to do? I would appriciate any thoughts or input.