The DS18B20 digital temperature sensor is easy to wire and can be used in a variety of occasions after packaging, such as pipeline type, threaded type, magnet adsorption type, stainless steel package type, and various models, including LTM8877, LTM8874, etc. Its appearance is mainly changed according to different application occasions. The packaged DS18B20 can be used for cable trench temperature measurement, blast furnace water circulation temperature measurement, boiler temperature measurement, machine room temperature measurement, agricultural greenhouse temperature measurement, clean room temperature measurement, warehouse temperature measurement and other non-extreme temperature occasions. It is wear-resistant and collision-resistant, small in size, easy to use, and has a variety of packaging forms. It is suitable for various digital temperature measurement and control fields of equipment in small spaces.
Technical performance description
1. Unique single-wire interface mode. When DS18B20 is connected to a microprocessor, only one line is needed to realize two-way communication between the microprocessor and DS18B20.
2. Temperature measurement range: -55℃~+125℃, inherent temperature measurement resolution: 0.5℃.
3. Support multi-point networking function. Multiple DS18B20 can be connected in parallel on a single three-wire.
4. Working power supply: 3~5V/DC
5. No peripheral components are required during use
6. The measurement results are transmitted serially in the form of 9~12-bit digital quantities
DS18b20 package
DS18B20 pin functions: GND voltage ground • DQ single data bus • VDD power supply voltage • NC empty pin
Connection between DS18b20 and processor
DS18B20 working principle and application
The temperature detection and digital data output of DS18B20 are fully integrated on one chip, so it has stronger anti-interference ability. Its one working cycle can be divided into two parts, namely temperature detection and data processing. Before explaining its working process, it is necessary to understand the internal memory resources of 18B20. 18B20 has three forms of memory resources. They are:
ROM Read Only Memory:
Used to store the DS18B20 ID code. The first 8 bits are the single-line serial code (DS18B20 code is 19H), the next 48 bits are the chip's unique serial number, and the last 8 bits are the CRC code (redundancy check) of the above 56 bits. The data is set at production and cannot be changed by the user. DS18B20 has a total of 64 bits of ROM.
RAM Data Register:
Used for internal calculation and data access. Data is lost after power failure. DS18B20 has 9 bytes of RAM, each byte is 8 bits. The 1st and 2nd bytes are the data value information after temperature conversion. The 3rd and 4th bytes are the mirror images of the user's EEPROM (commonly used for temperature alarm value storage). Its value will be refreshed when power is reset. The 5th byte is the mirror image of the user's 3rd EEPROM. The 6th, 7th and 8th bytes are count registers, which are designed to allow users to obtain higher temperature resolution. They are also temporary storage units for internal temperature conversion and calculation. The 9th byte is the CRC code of the first 8 bytes. EEPROM is a non-volatile memory used to store data that needs to be saved for a long time, upper and lower temperature alarm values and verification data. DS18B20 has 3 bits of EEPROM, and there are mirror images in RAM to facilitate user operation.
Controller operation process for 18B20:
1. Reset: First we must reset the DS18B20 chip. Reset means the controller (MCU) sends a low level signal of at least 480uS to the DS18B20 single bus. When 18B20 receives this reset signal, it will send back a chip existence pulse after 15~60uS.
2. Presence pulse: After the reset level ends, the controller should pull up the data single bus to receive the presence pulse after 15~60uS. The presence pulse is a 60~240uS low-level signal. So far, the two parties have reached a basic agreement, and the next step will be data communication between the controller and 18B20. If the reset low level time is insufficient or the single bus circuit is broken, the presence pulse will not be received. Pay attention to the handling of unexpected situations during design.
3. The controller sends ROM instructions: After the two parties have said hello, they will communicate. There are 5 ROM instructions in total, and only one can be sent in each working cycle. The ROM instructions are read ROM data, specify matching chip, jump ROM, chip search, and alarm chip search. The ROM instruction is 8 bits in length, and its function is to operate the 64-bit photolithography ROM in the chip. Its main purpose is to distinguish and process multiple devices connected to a bus. It is true that multiple devices can be connected to a single bus at the same time, and they are distinguished by the unique ID number on each device. Generally, the ROM instruction can be skipped when only a single 18B20 chip is connected (Note: skipping the ROM instruction here does not mean not sending the ROM instruction, but using a unique "skip instruction")
4. The controller sends memory operation instructions: After the ROM instruction is sent to 18B20, the memory operation instruction is sent immediately (uninterruptedly). The operation instruction is also 8 bits, a total of 6, and the memory operation instructions are writing RAM data, reading RAM data, copying RAM data to EEPROM, temperature conversion, copying the alarm value in EEPROM to RAM, and working mode switching. The function of the memory operation instruction is to command 18B20 to do what kind of work, which is the key to chip control.
5. Execution or data reading and writing: After a memory operation instruction is completed, the instruction execution or data reading and writing will be carried out. This operation depends on the memory operation instruction. If the temperature conversion instruction is executed, the controller (MCU) must wait for 18B20 to execute its instruction. The general conversion time is 500uS. If the data reading and writing instruction is executed, it is necessary to strictly follow the reading and writing timing of 18B20 to operate.
To read the current temperature data, we need to execute two working cycles. The first cycle is reset, skip ROM instructions, execute temperature conversion memory operation instructions, and wait for 500uS temperature conversion time. Then execute the second cycle to reset, skip ROM instructions, execute RAM memory operation instructions, and read data (up to 9 bytes, which can be stopped in the middle. If you only read simple temperature values, just read the first 2 bytes). The other operation processes are similar, so I won’t introduce them here.
There are many online resources about the data sheet of ds18b20, so I won't introduce it in detail here. The following is a driver based on ARM-LINUX, which has been tested after being compiled by arm-gcc. (Original by Huaqing Yuanjian, please indicate the source when reprinting)
#include #define GPHCON (*(volatile unsigned int *)S3C2410_GPHCON) static int ds18b20_major = 230;/*Statically apply for device number*/ struct cdev cdev; spinlock_t lock; dev_t dev = 0; /*Configure to input mode*/ /*Configure to output mode*/ /*引脚置位*/ /*复位ds18b20*/ set_data(1); /*读取一位温度*/ /*写一位命令*/ /*写命令*/ if(reset_ds18b20()){
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
MODULE_LICENSE("GPL");
#define GPHDAT (*(volatile unsigned int *)S3C2410_GPHDAT)
#define GPHUP (*(volatile unsigned int *)S3C2410_GPHUP)
struct class *my_class;
int number_of_devices = 1;
void set_conIN(void)
{
GPHCON &= ~(1<<19);
GPHCON &= ~(1<<18);
}
void set_conOUT(void)
{
GPHCON |= (1<<18);
GPHCON &= ~(1<<19);
}
void set_data(int i)
{
if( i == 0 ){
GPHDAT &= ~(1<<9);
}else if( i == 1 ){
GPHDAT |= (1<<9);
}
}
unsigned int reset_ds18b20(void)
{
unsigned int retValue;
set_conOUT();
__udelay(1);
set_data(0);
__udelay(600);
set_data(1);
__udelay(20);
set_conIN();
__udelay(100);
/*After a short delay, if x=0, initialization is successful,
if x=1, initialization fails*/
retValue = (GPHDAT >> 9) & 0x01;
printk("init is %dn",retValue);
return retValue;
}
unsigned int read_bit(void)
{
spin_lock(&lock);
set_conOUT();
//set_data(1);
//__udelay(2);
set_data(0);
__udelay(2);
set_conIN();
__udelay(1);
spin_unlock(&lock);
return ((GPHDAT >> 9) & 0x01);
}
void write_bit(char bitValue)
{
spin_lock(&lock);
set_conOUT();
set_data(0);
__udelay(15);
if( bitValue == 1 ){
set_data(1);
}else{
set_data(0);
}
spin_unlock(&lock);
__udelay(45);
set_conIN();
__udelay(2);
}
void write_cmd(char cmd)
{
unsigned char i;
unsigned char temp;
for(i=0; i<8;i++){
temp = cmd>>i;
temp &= 0x01;
write_bit(temp);
}
//__udelay(10);
}
/*打开设备*/
static int ds18b20_open(struct inode *inode,struct file *filp)
{
printk (KERN_INFO "HEY! device openedn");
//GPHUP &= ~(1<<9);
GPHUP |= (1<<9);
spin_lock_init(&lock);
return 0;
}
/*读取数据*/
static int ds18b20_read(struct file *filp, char *buffer, size_t count, loff_t *ppos)
{
char lowValue=0,highValue=0;
unsigned int i;
//float value;
printk("init errorn");
}
__udelay(400);
set_conOUT();
set_data(1);
write_cmd(0xCC);
write_cmd(0x44);
__udelay(100000);
if(reset_ds18b20()){
printk("init errorn");
}
__udelay(400);
set_conOUT();
set_data(1);
write_cmd(0xcc);
write_cmd(0xBE);
/*读取温度转化数值*/
for(i=0; i<8; i++){
if( read_bit() ){
lowValue |= (0x01<}
__udelay(62);
}
printk("lowValue is %dn",lowValue);
for(i=0; i<8; i++){
if( read_bit() ){
highValue |= (0x01<}
__udelay(62);
}
printk("highValue is %dn",highValue);
#if 0
i = highValue;
i <<= 8;
i = i|lowValue;
value = i*0.0625;
printk("kernel is %dn",value);
#endif
Previous article:s3c2440A development board UART summary and UART code details
Next article:ARM Litian Electronics LPC2148 Detailed explanation of the temperature acquisition experimental procedure based on DS18b20
Recommended ReadingLatest update time:2024-11-17 04:52
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Single-chip microcomputer technology and application - electronic circuit design, simulation and production (edited by Zhou Runjing)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- Share the troubleshooting of using bq34z100 chip
- The salary and development path of hardware engineers
- MSP430 series MCU-Timer_A realizes PWM
- Here are some questions about the differential signal amplifier circuit
- [Gizwits Gokit 3 Review] Part 2: Product Creation
- RT-Thread device framework learning SPI device
- Motor Science Series丨Understanding Motor Control Algorithms
- A beginner was trapped by the garbage code of the development board for a whole night
- SinlinxA33 development board Linux platform bus device driver
- Broadband Matching Network_Huang Xiangfu《Scanned Version》