ADT7410是一款基于SOIC封装的高精度数字温度传感器。它内部具有带隙温度参考源以及13位ADC,可以提高0.0625摄氏度的温度精度。这个温度分辨率还可以改变成16位(0.0075℃)。
ADT7410可以工作在2.7V至5.5V的工作电源。工作在3.3V时,工作电流为210uA。 ADT在Shutdown模式下,耗电量仅为2uA。
ADT7410可以工作在-55℃至150℃。可被广泛 应用在医疗器械、环境监控、计算机温度检测、温度保护、工业过程控制、电源系统监测以及手持设备应用等等。
▲ ADT7410内部功能图
ADT7410通过I2C总线与MCU连接。本文通过制作基于STC8G1K08电路板,来访问四个温度传感器。
○ 原理图设计
▲ MCU原理图
▲ ADT7410芯片小板
▲ ADT7410 PCB板
通过温度板的右边四个电阻,来设定温度传感器的I2C地址:A1A0。具体设置如下图所示:
▲ ADT7410地址设置通过RA1234
控制小板的串口命令:
else IFARG0("rt") {
printf("%f ", ADT7410ReadT(0));
printf("%f ", ADT7410ReadT(1));
printf("%f ", ADT7410ReadT(2));
printf("%f\r\n", ADT7410ReadT(3));
} else IFARG0("rtx") {
printf("%04x ", ADT7410ReadTemp(0));
printf("%04x ", ADT7410ReadTemp(1));
printf("%04x ", ADT7410ReadTemp(2));
printf("%04x\r\n", ADT7410ReadTemp(3));
} else IFARG0("rtb") {
nNumber = ADT7410ReadTemp(0);
SendChar((unsigned char)(nNumber >> 8));
SendChar((unsigned char)(nNumber));
nNumber = ADT7410ReadTemp(1);
SendChar((unsigned char)(nNumber >> 8));
SendChar((unsigned char)(nNumber));
nNumber = ADT7410ReadTemp(2);
SendChar((unsigned char)(nNumber >> 8));
SendChar((unsigned char)(nNumber));
nNumber = ADT7410ReadTemp(3);
SendChar((unsigned char)(nNumber >> 8));
SendChar((unsigned char)(nNumber));
}
▲ 上电后实验电路板
本文构造可以同时访问四路ADT7410温度传感器。 通过串口命令可以获得对应的温度值。
▲ 测量白炽灯泡在点亮后的温度上升
▲ 测量制冷片的温度下降过程
▲ 测量制冷片的温度上升过程
/* **============================================================================== ** ADT7410.C: -- by Dr. ZhuoQing, 2020-07-08 ** **============================================================================== */
//------------------------------------------------------------------------------
#define ADT7410_GLOBALS 1 // Define the global variables
#include "ADT7410.H"
#include "STC8G.H"
//------------------------------------------------------------------------------
//==============================================================================
// INTERFACE FUNCTIONS
//------------------------------------------------------------------------------
void ADT7410SetAdd(unsigned char ucA10) {
g_ucADT7410Add = ADT7410_I2C_ADD + (ucA10 << 1);
}
//------------------------------------------------------------------------------
void ADT7410Init(unsigned char ucAdd) {
ADT7410SetAdd(ucAdd);
ADT7410SetConfiguration(0x80); // Set 16 bits resolution of temperature.
}
//------------------------------------------------------------------------------
float ADT7410ReadT(unsigned char ucAdd) {
ADT7410SetAdd(ucAdd);
ADT7410SetConfiguration(0x80);
return ADT7410ReadTemperature() / 128.0;
}
//------------------------------------------------------------------------------
int ADT7410ReadTemp(unsigned char ucAdd) {
ADT7410SetAdd(ucAdd);
ADT7410SetConfiguration(0x80);
return ADT7410ReadTemperature();
}
//------------------------------------------------------------------------------
float ADT7410Temperature(int nNumber) {
return nNumber / 128.0;
}
//------------------------------------------------------------------------------
void ADT7410WriteByte(unsigned char ucAdd, unsigned char ucByte) {
I2CStart();
I2CSendData(g_ucADT7410Add);
I2CReceiveACK();
I2CSendData(ucAdd);
I2CReceiveACK();
I2CSendData(ucByte);
I2CReceiveACK();
I2CStop();
}
void ADT7410WriteInt(unsigned char ucAdd, unsigned int nNum) {
I2CStart();
I2CSendData(g_ucADT7410Add);
I2CReceiveACK();
I2CSendData(ucAdd);
I2CReceiveACK();
ucAdd = (unsigned char)(nNum >> 8);
I2CSendData(ucAdd);
I2CReceiveACK();
ucAdd = (unsigned char)(nNum);
I2CSendData(ucAdd);
I2CReceiveACK();
I2CStop();
}
//------------------------------------------------------------------------------
unsigned char ADT7410ReadByte(unsigned char ucAdd) {
unsigned char ucByte;
I2CStart();
I2CSendData(g_ucADT7410Add);
I2CReceiveACK();
I2CSendData(ucAdd);
I2CReceiveACK();
I2CStart();
I2CSendData(g_ucADT7410Add + 1);
ucByte= I2CReceiveData();
I2CSendNACK();
I2CStop();
return ucByte;
}
void ADT7410ReadDim(unsigned char ucAdd, unsigned char ucLength, unsigned char * pDim) {
unsigned char ucByte, i;
I2CStart();
I2CSendData(g_ucADT7410Add);
I2CReceiveACK();
I2CSendData(ucAdd);
I2CReceiveACK();
I2CStart();
I2CSendData(g_ucADT7410Add + 1);
I2CReceiveACK();
for(i = 0; i < ucLength; i ++) {
ucByte= I2CReceiveData();
if(i < ucLength - 1)
I2CSendACK();
else I2CSendNACK();
*(pDim + i) = ucByte;
}
I2CStop();
}
//------------------------------------------------------------------------------
int ADT7410ReadTemperature(void) {
unsigned char ucBytes[2];
int nValue;
ADT7410ReadDim(0x0, 2, ucBytes);
// ucBytes[0] = ADT7410ReadByte(0);
// ucBytes[1] = ADT7410ReadByte(1);
nValue = ucBytes[0];
nValue = (nValue << 8) | ucBytes[1];
return nValue;
}
unsigned char ADT7410ReadStatus(void) {
unsigned char ucChar;
ucChar = ADT7410ReadByte(ADT7410_STATUS_ADD);
return ucChar;
}
unsigned char ADT7410ReadConfiguration(void) {
unsigned char ucChar;
ucChar = ADT7410ReadByte(ADT7410_CONFIGURATION_ADD);
return ucChar;
}
void ADT7410SetConfiguration(unsigned char ucConfiguration) {
ADT7410WriteByte(ADT7410_CONFIGURATION_ADD, ucConfiguration);
}
unsigned char ADT7410ReadID(void) {
unsigned char ucChar;
ucChar = ADT7410ReadByte(ADT7410_ID_ADD);
return ucChar;
}
void ADT7410SoftwareReset(void) {
ADT7410WriteByte(ADT7410_RESET_ADD, 0xaa);
}
void ADT7410SetHysteresisTemperature(unsigned char ucHysteresis) {
ADT7410WriteByte(ADT7410_THYST_ADD, ucHysteresis);
}
void ADT7410SetHighTemperature(int nT) {
ADT7410WriteInt(ADT7410_THIGH_ADD, nT);
}
void ADT7410SetLowTemperature(int nT) {
ADT7410WriteInt(ADT7410_TLOW_ADD, nT);
}
void ADT7410SetCriticalTemperature(int nT) {
ADT7410WriteInt(ADT7410_TCRIT_ADD, nT);
}
int ADT7410ReadHighTemperature(void) {
unsigned char ucBytes[2];
int nValue;
ADT7410ReadDim(ADT7410_THIGH_ADD, 2, ucBytes);
nValue = ucBytes[0];
nValue = (nValue << 8) | ucBytes[1];
return nValue;
}
int ADT7410ReadLowTemperature(void) {
unsigned char ucBytes[2];
int nValue;
ADT7410ReadDim(ADT7410_TLOW_ADD, 2, ucBytes);
nValue = ucBytes[0];
nValue = (nValue << 8) | ucBytes[1];
return nValue;
}
int ADT7410ReadCritialTemperature(void) {
unsigned char ucBytes[2];
int nValue;
ADT7410ReadDim(ADT7410_TCRIT_ADD, 2, ucBytes);
nValue = ucBytes[0];
nValue = (nValue << 8) | ucBytes[1];
return nValue;
}
unsigned char ADT7410ReadHysteresisTemperature(void) {
return ADT7410ReadByte(ADT7410_THYST_ADD);
}
//==============================================================================
// END OF THE FILE : ADT7410.C
//------------------------------------------------------------------------------
/* **============================================================================== ** ADT7410.H: -- by Dr. ZhuoQing, 2020-07-08 ** ** Description: ** **============================================================================== */
#ifndef __ADT7410__
#define __ADT7410__
//------------------------------------------------------------------------------
#ifdef ADT7410_GLOBALS
#define ADT7410_EXT
#else
#define ADT7410_EXT extern
#endif // ADT7410_GLOBALS
//------------------------------------------------------------------------------
//==============================================================================
//------------------------------------------------------------------------------
#define ADT7410_I2C_ADD 0x90
ADT7410_EXT unsigned char g_ucADT7410Add;
void ADT7410SetAdd(unsigned char ucA10);
float ADT7410Temperature(int nNumber);
//------------------------------------------------------------------------------
float ADT7410ReadT(unsigned char ucAdd);
int ADT7410ReadTemp(unsigned char ucAdd);
//==============================================================================
// INTERFACE FUNCTIONS
//------------------------------------------------------------------------------
void ADT7410Init(unsigned char ucA10);
void ADT7410WriteByte(unsigned char ucAdd, unsigned char ucByte);
void ADT7410WriteInt(unsigned char ucAdd, unsigned int nNum);
unsigned char ADT7410ReadByte(unsigned char ucAdd);
void ADT7410ReadDim(unsigned char ucAdd, unsigned char ucLength, unsigned char * pDim);
//------------------------------------------------------------------------------
#define ADT7410_TEMPERATURE_ADD 0x0
#define ADT7410_STATUS_ADD 0x2
#define ADT7410_CONFIGURATION_ADD 0x3
#define ADT7410_THIGH_ADD 0x4
#define ADT7410_TLOW_ADD 0x6
#define ADT7410_TCRIT_ADD 0x8
#define ADT7410_THYST_ADD 0xA
#define ADT7410_ID_ADD 0x0B
#define ADT7410_RESET_ADD 0x2F
//------------------------------------------------------------------------------
int ADT7410ReadTemperature(void);
unsigned char ADT7410ReadStatus(void);
unsigned char ADT7410ReadConfiguration(void);
void ADT7410SetConfiguration(unsigned char ucConfiguration);
unsigned char ADT7410ReadID(void);
void ADT7410SoftwareReset(void);
void ADT7410SetHysteresisTemperature(unsigned char ucHysteresis);
void ADT7410SetHighTemperature(int nT);
void ADT7410SetLowTemperature(int nT);
void ADT7410SetCriticalTemperature(int nT);
int ADT7410ReadHighTemperature(void);
int ADT7410ReadLowTemperature(void);
int ADT7410ReadCritialTemperature(void);
unsigned char ADT7410ReadHysteresisTemperature(void);
//==============================================================================
// END OF THE FILE : ADT7410.H
//------------------------------------------------------------------------------
#endif // __ADT7410__
MCU控制板AD工程文件:AD\Test\2020\Tools\ADT7410STC8G1k.SchDoc * ↩︎
ADT7410印刷电路板设计工程文档:AD\Test\2020\Tools\ADT7410MOD.SchDoc ↩︎
STC8G 工程文件:C51\STC\Test\2020\Tools\ADT7410STC8G1K\ADT7410STC8G1K.uvproj ↩︎