Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

DS18B20 Code Examples

Status
Not open for further replies.

tpetar

Advanced Member level 7
Joined
Sep 27, 2010
Messages
6,417
Helped
1,713
Reputation
3,456
Reaction score
1,673
Trophy points
1,393
Location
Pancevo-Belgrade, Serbia
Activity points
37,363
MikroC example of usage DS18B20
Link : **broken link removed**

DS18B20 is 1-Wire interface digital thermometer that require one port pin (and ground) for communication, has a unique 64-bit serial code stored in an onboard ROM, can measure temperatures from -55C to +125 C (-67F to +257F),and user-selectable resolution from 9 to 12 bits.

Pin assignment, pin description and block diagram of DS18B20 shown below. The DS18B20 can be powered by an external supply on the Vdd pin, or powered by the DQ pin (parasite power mode). Stealing power from DQ pin saves a wire but comunication with it is more complicate than using external power supply. For more detail about powering the DS18B20 can be found in the powering the DS18B20 section of its datasheet.



DS18B20 Memory

Scratchpad is 9 bytes of SRAM that organized as figer shown below. The first two bytes (byte 0 and byte 1) are read-only memory that contain the LSB and the MSB of the temperature register. Bytes 2 and 3 provide access to TH and TL registers. Byte 4 is a configuration register. Bytes 5,6 and 7 are reserved. Byte 8 is read-only and contains CRC code (cyclic redundancy check) for byte 0 through byte 7 of the scratchpad.

The output temperature data from DS18B20 is calibrated in degree centigrade and the default resolurion at power up is 12-bit. The temperature register format shown below, where as sign bits (S) indicate if the temperature is positive (S=0) or negative (S=1).

To access the DS18B20's data, 3 steps sequence as follows is need.

1. Initalization. All transections on the 1-wire bus begin with an initalization sequence. It consists of a reset pulse transmitted by the bus master followed by presence pulse transmitted by the slave. Timing for the reset and presence pulse is shown below.

2. Issue a ROM command after the bus master has detected a presence pulse. ROM commands are : Search ROM[F0h], Read ROM[33h], Match ROM[55h], Skip ROM[CCh] and Alarm Search[ECh].

3. Issue a DS18B20 function command after a ROM command. A ROM command is to select which DS18B20 that the master want to communicate with. A function command allows the master to read and to write from the DS18B20's scratchpad, etc. DS18B20 function commands are: Convert T[44h], Write Scratchpad[4Eh], Read Scratchpad[BEh], Copy Scratchpad[48h], Recall E2[B8h], and Read Power Supply[B4h].

It is very important to follow this sequence every time the DS18B20 is accessed. Exceptions to this rule are Search ROM[F0] and Alarm Search[EC] commands. The master must return to step 1 after issue either of those ROM commands.

Read/Write signaling.

All data and commands are transmitted least significant bit first over the 1-Wire bus. The figure shown below is Read/Write timing diagram. All Read/Write time slots must be 60 usec in duration with a minimum of a 1 usec recovery time between individual read/write slots. To write "1" the bus master pull low and release within 15 usec. To write "0", after pulling the bus low, the bus master must continue stay low for 60 usec minimum then release the bus. To read logical from DS18B20, the bus master must pull low for at least 1 usec then release the bus then master must sample the signal within 15 usec from the start of the slot.

Rest info and code you can find on original web link....
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top