Previous in Forum: Do You Know the FDS9435A Chip? Can This Chip be Directly Controlled by FPGA?   Next in Forum: Smartphone Discharging Question
Close
Close
Close
4 comments
Rate Comments: Nested
Participant

Join Date: Jun 2019
Posts: 4

Why Can't My DS18B20 Always Initialize?

11/29/2019 8:43 AM

// Delay 2 microseconds subroutine (12MHZ)

void delay_2us (unsigned char i)

{while (-i);}

void init_ds18b20 ()

{

uchar x = 0;

DQ = 1; / * First pull high to prepare for reset * /

delay_2us (24); / * delay it a bit * /

DQ = 0; / * pull the level low, delay at least 480us * /

delay_2us (240); / * Delay here 480us * /

DQ = 1; / * After the reset signal is given, pull the level high and wait for the existence pulse * /

delay_2us (30); / * Delay 15 ~ 60us, here delay 60us, give the existence pulse time * /

x = DQ; / * Read existence pulse * /

delay_2us (240); / * Read the presence pulse, the low-level signal whose presence pulse is at least 60us to 240us, here 480us * /

while (1)

{

if (x == 1)

display (1,1,1,1); Initialization failed to display 1111

else

display (0,0,0,0); // Display 0000 after initialization

}

DQ = 1; / * After reading, the signal is reset, DS18B20 is initialized, and data exchange protocol is generated * /

}

After tuning for a long time, it still shows 1111.

What is the reason?

Register to Reply
Pathfinder Tags: DS18B20
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.

Good Answers:

These comments received enough positive votes to make them "good answers".
2
Guru

Join Date: Apr 2010
Location: About 4000 miles from the center of the earth (+/-100 mi)
Posts: 9911
Good Answers: 1141
#1

Re: Why can't my DS18B20 always initialize?

11/29/2019 9:46 AM

https://cdn.sparkfun.com/datasheets/Sensors/Temp/DS18B20.pdf

Is the signal line accessible to monitor with an oscilloscope?

The datasheet specifies 480us minimum, try increasing the delay.

Register to Reply Good Answer (Score 2)
Participant

Join Date: Jun 2019
Posts: 4
#4
In reply to #1

Re: Why can't my DS18B20 always initialize?

12/03/2019 8:33 AM

I adjusted the delay and the problem was solved! Thank you!

Register to Reply
Guru
Popular Science - Cosmology - Let's keep knowledge expanding Engineering Fields - Retired Engineers / Mentors - Hobbies - HAM Radio - New Member

Join Date: Dec 2006
Location: North America, Earth
Posts: 4528
Good Answers: 106
#2

Re: Why can't my DS18B20 always initialize?

11/29/2019 1:23 PM

In addition to Rixter's answer make sure you have a bypass capacitor near the device.

__________________
“I would rather have questions that can't be answered than answers that can't be questioned.” - Richard Feynman
Register to Reply
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#3

Re: Why can't my DS18B20 always initialize?

11/30/2019 2:05 AM
__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply
Register to Reply 4 comments

Good Answers:

These comments received enough positive votes to make them "good answers".
Copy to Clipboard

Users who posted comments:

Mikerho (1); Rixter (1); sheng Ke (1); StandardsGuy (1)

Previous in Forum: Do You Know the FDS9435A Chip? Can This Chip be Directly Controlled by FPGA?   Next in Forum: Smartphone Discharging Question

Advertisement