DS18B20 uses a single bus for data transmission, so the timing requirements are very high. It is very necessary to learn how to analyze its timing diagram.
1. Initialization timing diagram analysis:
First, the bus controller pulls the bus down for 480us. After 480us, the bus is released and the pull-up resistor pulls the bus up. After waiting for 5-60us, the DS18B20 starts to respond and pulls the data bus down for 60-240us. After that, the bus is released and the pull-up resistor pulls the bus up. The converted code is as follows:
u8dsbInit() // Initialization, return 0 means DS18B20 has no response, otherwise it has a response
{
dsbDQStat(0); //Controller pulls down the bus
delay500us(); //Pull the bus down for a while
dsbDQStat(1); //Release the bus
delay60us(); //wait for DS18B20 response
if(dsb_DQ) // if there is no response, return 0 directly
{
return0;
}
delay240us(); //If there is a response, wait for the response to end
return1; //Return to initialization state
}
2. Read the timing diagram analysis:
First, the controller pulls the bus down for >1us, then the controller releases the bus. If the controller samples a low level at this time, the read value is 0, if it is a high level, the read value is 1. Note that there is a 15us marked in the figure, which means that the controller sampling is completed within 15us. After 15us, the bus is pulled up by the pull-up resistor and maintained for 45us. The entire read cycle is 15+45=60us. The time of this cycle must also be controlled. The conversion code is as follows:
u8dsbReadByte() //Read a byte of data, starting from the low bit
{
u8i,tmp=0;
for(i=0;i<8;i++)
{
dsbDQStat(0); //Controller pulls down the bus
tmp>>=1; //Start reading from low bit
dsbDQStat(1); //Release the bus
if(dsb_DQ)tmp|=0x80;
delay15us();
delay45us(); //control cycle time
}
returntmp;
}
3. Write timing diagram analysis:
First, the controller pulls the bus down for 15us. After that, if you want to write 0, the bus will continue to be pulled down for 45us. If you want to write 1, the bus will be released and the pull-up resistor will pull the bus up for 45us. The write sequence is relatively simple and can be converted into code as follows:
void dsbWriteByte(u8dat) //Write a byte of data, starting from the low bit
{
u8i;
for(i=0;i<8;i++)
{
dsbDQStat(0); //Controller pulls down the bus
delay15us(); //maintain 15us
if(dat&0x01)dsbDQStat(1);
elsedsbDQStat(0);
dat>>=1;
delay45us();
dsbDQStat(1); //Release the bus after 45us
}
}
The three timing diagrams of DS18B20 have been analyzed. DS18B20 is just an example of single-bus data communication. Now that you have learned the analysis of the DS18B20 timing diagram, you can try to analyze the DHT11 timing diagram to complete its initialization function and data reading function.
Previous article:Application of RS-232 serial communication in communication between PC and single chip microcomputer
Next article:Suggestions for MCU beginners to better learn MCU
Recommended ReadingLatest update time:2024-11-16 13:50
- 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!
- 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
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- #Idle Market# is open, you sell your idle items and I'll give you gifts!
- Research on integrated navigation algorithm in case of GPS signal loss.pdf
- I want to build a data access platform for NB-IOT devices based on the COAP protocol. In addition to LIBCOAP, what other technologies are used?
- Beijing's first bicycle lane, 6.5 kilometers, 20 minutes, check-in successful
- How to make a sensorless brushless DC motor driver board
- Today at 10:00 AM, live broadcast with awards: Internet of Everything - Shijian Company and Microchip experts jointly discuss IoT solutions
- What are the advantages and disadvantages of MOS tubes and relays as electronic switches? In what situations would relays or MOS tubes be preferred?
- Looking for domestic wireless charging chip manufacturers
- Detailed explanation of 5G OTA testing technology
- Analog IC Design Resource Download