Hardware Reference
In-Depth Information
One common temperature sensor is the DS1631 I2C. It is essential to review the characteristics of the device in
order for the code to use these features. This includes going to the data sheet http://datasheets.maxim-ic.com/en/
ds/DS1631-DS1731.pdf , on which you can derive the following information.
This is an I2C slave device, which has a pin configurable address for up to eight devices on the same I2C chain as
the master device.
This is represented by the 7-bit control byte defined here:
Bit 0: r/w
Bit 1: A0
Bit 2: A1
Bit 3: A2
Bit 4: 1
Bit 5: 0
Bit 6: 0
Bit 7: 1
We frequently work with these numbers in hexadecimal format. You will see device configuration that looks like this:
0x90
The way to read it is:
9 is 1001
0 is 0000
That would mean the device address is 0 and writable. The address corresponds to three bits, A0, A1, A2, and the
last bit in the sequence configures if the device is in both write and read mode. So, read-only would look like 0001. The
address only needs the 000, so in the implementation, we shift the address by one bit. Then the piece of code looks
like this:
_addr = 0x90 >> 1;
Now the address can be used to reference the device. The goal with our code is to put those details into the
constructor so that the data sheet can be directly read and the address can be pulled from it without forcing the
programmer to make the shift. This also means that the user must wire the DS1631 with a valid address. Then, they
must define the address for the library or object. When we configure the object, we require an address. The Arduino
I2C master sets the control byte in order to tell the correct DS1631 what command to receive.
Ideally, the programmer will be able to use or hide the commands as needed during the implementation stage.
So, startConversion() can be done without the programmer knowing the internal commands, such as the fact that
0x51 means “start conversion”. This applies to any of the appropriate and defined commands. For use in the Wire
library, these must be converted into a hexadecimal form.
The commands are as follows:
Start Convert: 0x51
Stop Convert: 0x22
Read Temperature: 0xAA
Access TH: 0xA1
 
Search WWH ::




Custom Search