Reading the temperature with a DS1631 Maxim Temperature Sensor

(Software I2C C code)

The datasheet for the DS1631 can be found here

The DS1631 comes in both PDIP and SOIC. I first used the SOIC version. I just soldered wires onto each lead and used clips to attach them to the I2C port of the Futurlec 2313 Dev board.



The output of this program is to the UART (ie can be read by your PC via serial port). The output is a decimal number representing the integer of the temperature the chip is currently experiencing. The chip is more accurate than this but I didn't need anything more than the integer so the program doesn't display anything more than the integer. I may fix this later.

The output will not show up as ASCII text. It will be outputed as the raw decimal value. I intend to fix this later. Stay tuned for updates.

I suggest Bray's terminal to read the output ( as this program is capable of outputting the raw decimal value to the PC screen.

I2C address

The program assumes you have attached pins a1, a2 and a3 of the DS1631 to GND. These pins set the I2C address of the device. If you have changed this then you just need to adjust the 0x90 in the line:

#define DEV_DS1631 0x90 //I2C slave address of the ds1631 with a1-3 to GND

To whatever number you have assigned the device.( See the DS1631 datasheet for further info)

Pins used

This software I2C implementation (bit-bang) uses pin 5 and 6 of Port D. Thus PD5 and PD6 as can be seen below. This can be changed by the #defines in the .c file. BEWARE: If you do this, there are one or two hard-coded "magic numbers" in the code. I have commented where this happens. You will need to alter the "magic-numbers" to have the program work correctly. Failing to do this will result in some really funny errors. I intend to fix this later. Email me if you have problems.


Pin labels from datasheet