DS18B20 Related Summary

Publisher:csZhouLatest update time:2015-05-07 Source: 51heiKeywords:DS18B20 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

 

    ROM read-only memory is used to store DS18B20 ID code. The first 8 bits are single-line serial code (DS18B20 code is 19H), the following 48 bits are the unique serial number of the chip, and the last 8 bits are the CRC code (redundancy check) of the above 56 bits. The data is set at the time of production and cannot be changed by the user. DS18B20 has a total of 64 bits of ROM. 
    
    RAM data register is used for internal calculation and data access. The data is lost after power failure. DS18B20 has a total of 9 bytes of RAM, each byte is 8 bits. The first and second bytes are the data value information after temperature conversion, and the third and fourth bytes are the mirror image of the user's EEPROM (commonly used for temperature alarm value storage). Its value will be refreshed at power-on reset. The fifth byte is the mirror image of the user's third EEPROM. The sixth, seventh, and eighth 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 ninth byte is the CRC code of the first 8 bytes. EEPROM is a non-volatile memory used to store long-term data, upper and lower temperature alarm values ​​and calibration data.

    DS18B20 has a total of 3 bits of EEPROM, and both are mirrored in RAM for user convenience.


Controller operation process for 18B20:

1. Reset: First we must reset the DS18B20 chip. Reset means that the controller (single-chip microcomputer) gives the DS18B20 single bus a low-level signal of at least 480uS. When 18B20 receives this reset signal, it will send back a chip presence pulse after 15~60uS.
 
2. Presence pulse: After the reset level ends, the controller should pull up the data single bus to facilitate receiving the presence pulse after 15~60uS. The presence pulse is a 60~240uS low-level signal. So far, the two parties in communication 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 circuit of the single bus 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 long 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 can be 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 the memory operation instruction: After the ROM instruction is sent to the 18B20, the memory operation instruction is sent immediately (uninterruptedly). The operation instruction is also 8 bits, a total of 6. 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 switching the working mode. The function of the memory operation instruction is to command 18B20 to do what kind of work, which is the key to chip control. [page]
 
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 (microcontroller) must wait for 18B20 to execute its instruction. The general conversion time is 500uS. If the data read and write instruction is executed, it is necessary to strictly follow the read and write timing of 18B20 to operate. The data reading and writing method will be described in detail below. 
 
    If we want to read the current temperature data, we need to execute two working cycles. The first cycle is reset, skip ROM instruction, execute temperature conversion memory operation instruction, and wait for 500uS temperature conversion time. The second cycle is then executed to reset, skip ROM instructions, execute the memory operation instruction of reading RAM, and read data (up to 9 bytes, which can be stopped in the middle. If you only read the simple temperature value, just read the first 2 bytes). The other operation processes are similar and will not be introduced here. 


DS28B20 chip ROM instruction table: 
 
Read ROM [33H] (the command word in square brackets is in hexadecimal) This command allows the bus controller to read the 64-bit ROM of DS18B20. This instruction can only be used when there is only one DS18B20 on the bus. If more than one is connected, data conflicts will occur during communication. 
 
Match ROM [55H] 
This instruction is followed by a 64-bit serial number issued by the controller. When there are multiple DS18B20s on the bus, only the chip with the same serial number as the one issued by the controller can respond, and the other chips will wait for the next reset. This instruction is suitable for single-chip and multi-chip connection. 
 
Skip ROM (skip ROM instruction) [CCH] 
This instruction makes the chip not respond to the ROM code. In the case of a single bus, this instruction can be used to save time. If this instruction is used when multiple chips are connected, data conflicts will occur, resulting in errors. 
 
Search ROM (search chip) [F0H] 
After the chip is initialized, the search instruction allows the 64-bit ROM of all devices to be identified by elimination when multiple chips are connected to the bus. 
 
Alarm Search (alarm chip search) [ECH] 
In the case of multiple chips, the alarm chip search instruction only responds to chips that meet the alarm conditions of temperatures higher than TH or less than TL. As long as the chip is not powered off, the alarm state will be maintained until the temperature is measured again and does not reach the alarm condition. 
 
 
DS28B20 chip memory operation instruction table: 
 
Write Scratchpad (write data to RAM) [4EH] 
This is an instruction to write data to RAM. The two bytes of data written subsequently will be stored in address 2 (TH of alarm RAM) and address 3 (TL of alarm RAM). The write process can be terminated by the reset signal. 
 
Read Scratchpad (read data from RAM) [BEH] 
This instruction will read data from RAM, starting from address 0 and continuing to address 9 to complete the reading of the entire RAM data. The chip allows the reset signal to terminate the reading process, that is, it is not necessary to read the following bytes to reduce the reading time.  
 
Copy Scratchpad (copy RAM data to EEPROM) [48H] 
This instruction stores the data in RAM into EEPROM to prevent the data from being lost when power is off. Since the chip is busy with EEPROM storage processing, when the controller sends a read time slot, the bus outputs "0", and when the storage work is completed, the bus will output "1". In parasitic working mode, a strong pull-up must be used immediately after issuing this instruction and maintained for at least 10MS to maintain the chip operation. 

Convert T (temperature conversion) [44H] 
After receiving this instruction, the chip will perform a temperature conversion and put the converted temperature value into the 1st and 2nd addresses of RAM. Since the chip is busy with temperature conversion, when the controller sends a read time slot, the bus outputs "0", and when the storage work is completed, the bus will output "1". In parasitic working mode, a strong pull-up must be used immediately after this instruction is issued and maintained for at least 500MS to maintain chip operation. 
 
Recall EEPROM (Copy the alarm value in EEPROM to RAM) [B8H] 
This instruction copies the alarm value in EEPROM to the 3rd and 4th bytes in RAM. Since the chip is busy with copying, when the controller sends a read time slot, the bus outputs "0", and when the storage work is completed, the bus will output "1". In addition, this instruction will be automatically executed when the chip is powered on and reset. In this way, the two alarm byte bits in RAM will always be a mirror image of the data in EEPROM. 
 
Read Power Supply (Working Mode Switching) [B4H] 
After this instruction is issued, a read time slot is issued, and the chip will return its power status word, "0" for parasitic power status and "1" for external power status.

Keywords:DS18B20 Reference address:DS18B20 Related Summary

Previous article:Detailed explanation of how to use #ifndef
Next article:Protues 3D view function

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号