Hardware Reference
In-Depth Information
Access TL: 0xA2
Access Config: 0xAC
Software POR: 0x54 Registers:
Temperature, 2 bytes, read only
Configuration, 1 byte, read/write or set read-only
Trip point: High, 2 bytes, read/write
Trip point: Low, 2 bytes, read/write
We will want to obtain and/or set this information. The trigger trip points are very useful because we can set
actions to occur if we leave a common boundary. Additionally, we can have interrupts that respond to both high and
low conditions.
We will not be using the trip point registers in this example, but they can be found with the website in the final
library code.
A typical set of functions would be the getters and setters for those registers:
getConfig();
setConfig();
getTemp();
The goal for the main Arduino sketch is to print out the temperature at specified intervals. When we distribute
the code, this will be moved into the examples folder. We also need to create DS1631.h , and DS1631.cpp in the same
sketch folder. Then, we will move the code to its own Arduino generic library. Here's the initial library code, starting
with the header file:
Listing 12-11. DS1631 I2C temperature sensor Arduino library DS1631.h
/*
* DS1631 library object.
* Registers R1, and R2 are used to set 9, 10, 11, 12 bit temperature resolution
* Between a range of -55C to +125C
* A0, A1, A2 are used to set the device address. Which is shifted by the library for use.
* 1-SHOT readings or Continuous Readings can be configured
* 12 bit resolution can take up to 750ms to be available
* Temperature is returned in a 16 bit two's complement Th, and Tl Register
* The signed bit S, S = 0 for positive, and S = 1 for negative
*/
#ifndef DS1631_h
#define DS1631_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include "pins_arduino.h"
#else
#include "WProgram.h"
#include "pins_arduino.h"
#endif
 
Search WWH ::




Custom Search