DS18B20 single bus data transmission

Publisher:恬淡如云Latest update time:2015-03-24 Source: diangonKeywords:DS18B20 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  A pure single-chip microcomputer cannot do much, and must be equipped with various peripherals. Therefore, it is essential to understand the data communication between the single-chip microcomputer and the sensor. Common single-chip microcomputer data communication methods include SPI, IIC, RS232, single bus, etc. Each communication method has a corresponding timing diagram. Analyzing the timing diagram and completing the code writing is a compulsory course for single-chip microcomputer learners. This article takes DS18B20 as an example to analyze single bus data transmission.

  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.

Analysis of single bus data transmission in single chip microcomputer data communication

  1. Initialization timing diagram analysis:

Analysis of single bus data transmission in single chip microcomputer data communication

  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:

Analysis of single bus data transmission in single chip microcomputer data communication

  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:

Analysis of single bus data transmission in single chip microcomputer data communication

  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.

Keywords:DS18B20 Reference address:DS18B20 single bus data transmission

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

51 MCU-Temperature Control-PID Algorithm-DS18B20-C Language
#include #include intrins.h #include math.h #include string.h struct PID { unsigned int SetPoint; // Set the desired value unsigned int Proportion; // Proportional Const unsigned int Integral; // Integral Const unsigned int Derivative; // differential constant Derivative Const unsigned int LastError;
[Microcontroller]
51 single-chip multi-channel DS18B20 temperature measurement display and serial number reading
/**************************************************** Function: Read serial number and match serial number, and read temperature value Multifunctional test board showing multi-channel temperature acquisition Normally display the temperature of 2 DS18B20 Read the DS18B20 serial number normally Microcontroller: STC1
[Microcontroller]
51 single-chip multi-channel DS18B20 temperature measurement display and serial number reading
DS18B20 assembly program and C program
ds18b20 c program //DS1820 C51 subroutine //Here we take 11.0592M crystal as an example. Different crystal speeds may require adjustment of the delay time //sbit DQ = P2^1; //Define the port according to actual conditions  typedef unsigned char byte; typedef unsigned int word; //delay void delay(word useconds) { for
[Microcontroller]
DHT11 and DS18B20 temperature and humidity control microcontroller program
Based on 51 single chip microcomputer, the sensor uses dht11 and ds18b20. The temperature measurement accuracy of dht11 is limited, and 18b20 can make up for it. The first line shows the humidity and temperature collected by dht11, as well as the relay status. The second line shows the temperature and THI collected by
[Microcontroller]
DHT11 and DS18B20 temperature and humidity control microcontroller program
DS18B20 temperature measurement and display program
#include #include intrins.h sbit TSOR=P2^0; #define Busy 0x80; #define uchar unsigned char #define uint unsigned int #define reset() {WDT=0x1e;WDT=0xe1;} sfr WDT=0xa6; bit ON_OFF; bit outflag; sbit en =P1^7; /*DTLED-6 display chip enable terminal*/  sbit dout=P1^6; /*DTLED-6 display chip data reading termi
[Microcontroller]
C language program using DS18B20 temperature sensor in single chip microcomputer (reference 6)
/******************************************/ // // DS18B20 thermometer C program // 2007.06.08 /******************************************/ //Use AT89C2051 microcontroller, 12MHZ crystal oscillator, common anode LED digital tube //P1 port outputs segment code, P3 port scans, P3.4 connects to DS18B20 #include "r
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号