TMP102 Temperature Sensor
- TMP102 Temperature Sensor
- Location
- Type
- Background
- Overview
- Detailed Design
- API
- Device Address Configuration
- Initialization
- Obtaining Temperature Readings
- Caveats
- Future Advancements
- Testing Plan
- Unit Testing Scheme
- Demonstration Project
Location
devices
Type
Implementation
Background
The Tmp102 utilizes I2C for communication and is capable of measuring temperatures ranging between -40˚C and +125˚C. A maximum of four sensors can be used simultaneously. The device’s serial bus address is configurable by connecting the address pin to one of four available connections.
The data-sheet for the device can be found here.
Overview
Communication with the device uses typical I2C. Temperature data is obtained in degrees Celsius and data bytes are transmitted with the most significant bytes first.
Detailed Design
API
namespace sjsu
{
class Tmp102 final : public TemperatureSensor
{
public:
struct DeviceAddress
{
public:
static constexpr uint8_t kGround = 0b100'1000;
static constexpr uint8_t kVoltageHigh = 0b100'1001;
static constexpr uint8_t kSda = 0b100'1010;
static constexpr uint8_t kScl = 0b100'1011;
};
struct RegisterAddress
{
public:
static constexpr uint8_t kTemperature = 0x00;
static constexpr uint8_t kConfiguration = 0x01;
};
static constexpr uint8_t kOneShotShutdownMode = 0x81;
static constexpr std::chrono::milliseconds kConversionTimeout = 30ms;
explicit constexpr Tmp102(
sjsu::I2c & i2c,
uint8_t device_address = sjsu::Tmp102::DeviceAddress::kGround);
Status Initialize() const override;
Status GetTemperature(
units::temperature::celsius_t * temperature) const override;
private:
void OneShotShutdown() const;
const sjsu::I2c & i2c_;
const uint8_t kDeviceAddress;
};
} // namespace sjsu
Device Address Configuration
The device address can be configured by connecting the address pin, A0, to either GND, V+, SDA, or SCL. This allows up to four Tmp102 devices to be used simultaneously.
Device Address | A0 Pin Connection |
---|---|
0b100'1000 | Ground |
0b100'1001 | V+ |
0b100'1010 | SDA |
0b100'1011 | SCL |
Table 1. List of available device addresses.
Initialization
explicit constexpr Tmp102(
sjsu::I2c & i2c,
uint8_t device_address = sjsu::Tmp102::DeviceAddress::kGround);
Status Initialize() const override
I2c
peripheral and returns the initialization status.
Obtaining Temperature Readings
The device is configured for one-shot shutdown mode when taking temperature readings to conserve power. That is, the device will take the temperature reading once and then shutdown until another reading is requested. Each reading requires a typical conversion time of 26µs.
static constexpr uint8_t kOneShotShutdownMode = 0x81;
void OneShotShutdown() const;
Status GetTemperature(
units::temperature::celsius_t * temperature) const override;
Caveats
N/A
Future Advancements
N/A
Testing Plan
Unit Testing Scheme
An I2c
driver shall be mocked and injected to the driver.
The following functions will be tested:
- Initialize()
- Should return Status::kSuccess
.
- GetTemperature()
- The call count of the I2c
method Transaction()
should be exactly 2
.
Demonstration Project
A demonstration project using the LPC17xx platform can be found here.