They have put the I2C address of the HDC1000 in a variable _i2caddr.
They cast the _i2caddr to a uint8_t, and they cast the number 4 to a uint8_t. I don't know why, I think that is not needed.
The default for a number (for example number 4) is an integer. They cast it to a 8-bits unsigned byte.
uint32_t Adafruit_HDC1000::read32(uint8_t a, uint8_t d) {
Wire.beginTransmission(_i2caddr);
Wire.write(a);
Wire.endTransmission();
delay(50);
Wire.requestFrom((uint8_t)_i2caddr, (uint8_t)4);
uint32_t r = Wire.read();
r <<= 8;
r |= Wire.read();
r <<= 8;
r |= Wire.read();
r <<= 8;
r |= Wire.read();
//Serial.println(r, HEX);
return r;
}
Wire.requestFrom() tells it to read the specified number of bytes from the device (and it then gets them with Wire.read() one at a time, and reassembles them into a 32-bit unsigned integer).
Prior to the request from, it sends a single byte (a, the first argument to the function) - this probably sets the address (within the device's internal memory map) that the subsequent requestFrom() will read starting at. (while the I2C standard doesn't specify it, this convention is very common in I2C devices)
Koepel:
They have put the I2C address of the HDC1000 in a variable _i2caddr.
They cast the _i2caddr to a uint8_t, and they cast the number 4 to a uint8_t. I don't know why, I think that is not needed.
The default for a number (for example number 4) is an integer. They cast it to a 8-bits unsigned byte.
C++ treats int and uint8_t (unsigned char) as different so unless you do the cast, there is no function with the proper arguments if the function is declared with uint8_t arguments and the caller arguments are int
The int is too big for the uint8_t so it is not a match.
"hex", "binary", and "decimal" are not encoding formats, but rather display formats.
that are determined by how you choose to display a value not by what the contents is.
For example, a byte in memory can be displayed as hex, binary, or decimal. The actual value never changes.
What you really may be asking, perhaps, is how is the data encoded.
The TI HDC1000 datasheet describes the data encoding in section 8.1
But since you seem to be using the Adafruit library, you don't have to concern yourself with such details.
You can use the API functions provided by the library to read the humidity and temperature and you can look in the library header file to see what those functions are and what they return.
Again, don't confuse the human readable output formats of hex,binary,decimal with data encoding.
The two are different.
To say a value is "decimal" in this context doesn't mean anything as any value communicated is hex, decimal, octal, and binary all at the same since those are simply output formats not encoding/storage formats
It is the data encoding format that matters.
The shift <<=8 and the OR |= are being used to construct a value that is larger than 8 bits.
This because the values from the part being read that are used to calculate the final temperature and humidity values are larger than 8 bits but are read 8 bits at a time.
To understand how the part works and the size and encoding of the data values for humidity and temperature you will need to read the datasheet and focus on section 8.
Section 8.1 explains the data encoding.
As to why you may be getting incorrect results from the adafruit readTemperature() and readHumidity() functions goes, that is probably best discussed in your other thread: http://forum.arduino.cc/index.php?topic=402026.0