Si7060 Temperature Sensor
- Si7060 Temperature Sensor
- Location
- Type
- Background
- Overview
- Detailed Design
- API
- Initialization
- Obtaining Temperature Readings
- Caveats
- Future Advancements
- Testing Plan
- Unit Testing Scheme
- Demonstration Project
Location
devices
Type
Implementation
Background
The Si7060 temperature sensor is a device utilizing I2C and capable of measuring temperatures ranging between -47.4°C to +157.39°C with recommended operating temperatures between -40°C to +125°C.
The data-sheet for the device can be found here.
Overview
Communication with the device uses typical I2C with temperature measurements obtained in degrees Celsius.
The I2c device address for this device is factory programmed. To determine the device address, refer to page 10, Section 5 in the data-sheet.
Detailed Design
API
namespace sjsu
{
class Si7060 final : public TemperatureSensor
{
public:
static constexpr uint8_t kDefaultAddress = 0x31;
static constexpr uint8_t kIdRegister = 0xC0;
static constexpr uint8_t kExpectedSensorId = 0x14;
static constexpr uint8_t kOneBurstRegister = 0xC4;
static constexpr uint8_t kAutomaticBitRegister = 0xC5;
static constexpr uint8_t kMostSignificantRegister = 0xC1;
explicit constexpr Si7060(sjsu::I2c & i2c, uint8_t address = kDefaultAddress);
Status Initialize() const override;
Status GetTemperature(
units::temperature::celsius_t * temperature) const override;
private:
const sjsu::I2c & i2c_;
uint8_t address_;
};
} // namespace sjsu
Initialization
Status Initialize() const override
I2c
peripheral.
2. Attempt to verify the device's connection by checking the device chip and
revision information register at address 0xC0. The resulting data byte should
always be 0x14
. If the device address does not match the expected address,
return Status::kDeviceNotFound
.
Obtaining Temperature Readings
Temperature readings are stored in two registers, the most significant byte register (Dspsigm) and the least significant byte register (Dspsigl). When the auto-increment option is enabled, the register pointer will be automatically incremented. Additionally, the device can be configured to operate in one-burst mode to conserve power by only performing one temperature conversion when requested.
Status GetTemperature(
units::temperature::celsius_t * temperature) const override
T (°C) = 55 + ((256 * Dspsigm[6:0] + Dspsigl[7:0] - 16384) / 160) = 55 + ((((Dspsigm[6:0] << 8) | Dspsigl[7:0]) - 16384) / 160)
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::kDeviceNotFound
when the I2c mock is stubbed to
initialize successfully and stubbed to output a device id of 0xFF
.
- Should return Status::kSuccess
when the I2c mock is stubbed to initialize
successfully and stubbed to output a device id of 0x14
.
- GetTemperature()
- The I2c mock shall be stubbed to output a temperature data of 0x66C1
.
- The call count of the I2c
method Transaction()
should be exactly 4
which consists of the following:
1. A write transaction to enable one-shot mode.
2. A write transaction to enable auto-increment.
3. A write transaction to register pointer to most significant byte
register and read the MSB of the temperature data.
4. A read transaction to retrieve the LSB of the temperature data.
- Should return a temperature value of ~117.006f
.
Demonstration Project
A demonstration project using the LPC40xx platform can be found here.