Application Note 120 Communicating Through the 1-Wire Master



Similar documents
Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

DS18B20 Programmable Resolution 1-Wire Digital Thermometer

PACKAGE OUTLINE DALLAS DS2434 DS2434 GND. PR 35 PACKAGE See Mech. Drawings Section

DS1821 Programmable Digital Thermostat and Thermometer

Introduction the Serial Communications Huang Sections 9.2, 10.2 SCI Block User Guide SPI Block User Guide

Embedded Systems Design Course Applying the mbed microcontroller

DS2401 Silicon Serial Number

AVR318: Dallas 1-Wire master. 8-bit Microcontrollers. Application Note. Features. Introduction

Serial Communications

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

DS1621 Digital Thermometer and Thermostat

NB3H5150 I2C Programming Guide. I2C/SMBus Custom Configuration Application Note

DS1990A-F5. Serial Number ibutton TM

AN141 SMBUS COMMUNICATION FOR SMALL FORM FACTOR DEVICE FAMILIES. 1. Introduction. 2. Overview of the SMBus Specification. 2.1.

LIN (Local Interconnect Network):

DS1621 Digital Thermometer and Thermostat

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

Microcontroller Based Low Cost Portable PC Mouse and Keyboard Tester

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

The I2C Bus. NXP Semiconductors: UM10204 I2C-bus specification and user manual HAW - Arduino 1

DS Wire Digital Thermometer and Thermostat

RETRIEVING DATA FROM THE DDC112

DS18B20-PAR 1-Wire Parasite-Power Digital Thermometer

MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence :

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

Arbitration and Switching Between Bus Masters

Part 1. MAX BIT DAC with an Arduino Board. MIDI to Voltage Converter Part1

AN601 I2C 2.8 Communication Protocol. SM130 SM130 - Mini APPLICATION NOTE

Block 3 Size 0 KB 0 KB 16KB 32KB. Start Address N/A N/A F4000H F0000H. Start Address FA000H F8000H F8000H F8000H. Block 2 Size 8KB 16KB 16KB 16KB

Dolphin In-Circuit programming Updating Firmware in the field

Microcontroller-based experiments for a control systems course in electrical engineering technology

HDMM01 V1.0. Dual-axis Magnetic Sensor Module With I 2 C Interface FEATURES. Signal Path X

An Introduction to MPLAB Integrated Development Environment

Digitale Signalverarbeitung mit FPGA (DSF) Soft Core Prozessor NIOS II Stand Mai Jens Onno Krah

HOST Embedded System. SLAVE EasyMDB interface. Reference Manual EasyMDB RS232-TTL. 1 Introduction

FM75 Low-Voltage Two-Wire Digital Temperature Sensor with Thermal Alarm

Computer Organization and Components

Von der Hardware zur Software in FPGAs mit Embedded Prozessoren. Alexander Hahn Senior Field Application Engineer Lattice Semiconductor

CAM-VGA100 User Manual

Command Processor for MPSSE and MCU Host Bus Emulation Modes

MMC314xMR. Ultra Small 3-axis Magnetic Sensor, With I 2 C Interface. Signal Path X. Signal Path Y. Signal Path Z FEATURES

Linux Driver Devices. Why, When, Which, How?

RS-485 Protocol Manual

MPR121 Serial Communication

USB / Data-Acquisition Module NOW LEAD-FREE

An Implementation Of Multiprocessor Linux

COMPUTER BASED REMOTE CONTROL FOR LAYOUT OF SCALED MODEL TRAINS

8051 hardware summary

Microtronics technologies Mobile:

Computer Systems Structure Input/Output

Serial port interface for microcontroller embedded into integrated power meter

A DIY Hardware Packet Sniffer

AND8336. Design Examples of On Board Dual Supply Voltage Logic Translators. Prepared by: Jim Lepkowski ON Semiconductor.

Eureka Technology. Understanding SD, SDIO and MMC Interface. by Eureka Technology Inc. May 26th, Copyright (C) All Rights Reserved

Kepware Technologies Optimizing KEPServerEX V5 Projects

The Programming Interface

Measurement and Analysis Introduction of ISO7816 (Smart Card)

Software User Guide UG-461

Serial Communications

HANDLING SUSPEND MODE ON A USB MOUSE

Production Flash Programming Best Practices for Kinetis K- and L-series MCUs

Lesson 16 Analog-to-Digital Converter (ADC)

UM I 2 C-bus specification and user manual. Document information

Allows the user to protect against inadvertent write operations. Device select and address bytes are Acknowledged Data Bytes are not Acknowledged

ST19NP18-TPM-I2C. Trusted Platform Module (TPM) with I²C Interface. Features

Freescale Semiconductor, I

TI ARM Lab 7 Accelerometers

COMPUTERS ORGANIZATION 2ND YEAR COMPUTE SCIENCE MANAGEMENT ENGINEERING UNIT 5 INPUT/OUTPUT UNIT JOSÉ GARCÍA RODRÍGUEZ JOSÉ ANTONIO SERRA PÉREZ

Application Note. Sharp Memory LCD Technology

Design of a High Speed Communications Link Using Field Programmable Gate Arrays

FPGA INTEGRATION MANUAL SATURN-SIL 2 MODULES. Dictionary Code. Edition 01. Revision 00. Number of pages 18

Application Note 132. Introduction. Voice Video and Data Communications using a 2-Port Switch and Generic Bus Interface KSZ MQL/MVL

Introduction: Implementation of the MVI56-MCM module for modbus communications:

INPUT/OUTPUT ORGANIZATION

AN LPC1700 timer triggered memory to GPIO data transfer. Document information. LPC1700, GPIO, DMA, Timer0, Sleep Mode

Booting from NAND Flash Memory

Modbus RTU Communications RX/WX and MRX/MWX

Kurz Instruments Inc. Document AV Document Title: MFTB Event Code Definitions. MFT B-Series Event Codes

8051 MICROCONTROLLER COURSE

DS9490R/DS9490B USB to 1-Wire/iButton Adapters

SafeSPI - Serial Peripheral Interface for Automotive Safety

Modbus Protocol. PDF format version of the MODBUS Protocol. The original was found at:

EMC6D103S. Fan Control Device with High Frequency PWM Support and Hardware Monitoring Features PRODUCT FEATURES ORDER NUMBERS: Data Brief

Table of Contents. Creating a VC1000 Network... 3

DAC Digital To Analog Converter

DS1307ZN. 64 x 8 Serial Real-Time Clock

Application Note 162 INTERFACING THE DS18X20/DS WIRE TEMPERATURE SENSOR IN A MICRO-CONTROLLER ENVIRONMENT.

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

Hello, and welcome to this presentation of the STM32L4 reset and clock controller.

Development Kit EM4095 User s Manual

MBP_MSTR: Modbus Plus Master 12

ETEC 2301 Programmable Logic Devices. Chapter 10 Counters. Shawnee State University Department of Industrial and Engineering Technologies

Why you need to monitor serial communication?

FR FAMILY MB91460 SPI - DAISY CHAIN COMMUNICATION 32-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

1 Wire TM Digital Thermometer

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

CSCA0102 IT & Business Applications. Foundation in Business Information Technology School of Engineering & Computing Sciences FTMS College Global

CHAPTER 11: Flip Flops

Implementing SPI Communication Between MSP430 G2452 and LTC ADC

Transcription:

www.dalsemi.com Application Note 120 Communicating Through the 1-Wire Master INTRODUCTION The DS1WM 1-Wire Master was created to facilitate host CPU communication with devices over a 1-Wire bus without concern for bit timing. This application note steps through a theoretical situation that will utilize every function of the 1-Wire Master for example purposes. It is assumed the reader has knowledge of the thermal sensor, the DS1WM 1-Wire Master, and Dallas Semiconductor s 1-Wire protocol. For more detailed information see [1] Book of ibutton Standards, [2] DS1WM Datasheet, [3] Datasheet, [4] Application Note 119 Embedding the 1-Wire Master. EXAMPLE CIRCUIT Figure 1 ASIC Host CPU INTR 1-Wire Master 1-Wire Bus CLK 50 MHz Figure 1 shows the circuit configuration this example will refer to. The 1-Wire Master has been designed into a customer ASIC and the host CPU will use it to order four thermal sensors to convert temperature and report their values. The 1-Wire bus and the INTR line each have a standard 5k pull-up resistor attached. A 50 MHz system clock drives the 1-Wire Master s timing through the CLK pin. The 1-Wire Master has been memory mapped into port address space of the CPU. OVERVIEW The code for this example is written in C. The main function is called GetTemperatures. It will initialize the 1-Wire Master, find all devices on the 1-Wire bus, ask those devices to measure temperature, and then store those temperature values. If no devices are present on the bus the function returns 1, it returns 0 otherwise. All other functions are described in detail below. The constant BASE in this example refers to the base address where the 1-Wire Master has been memory mapped. TEMPS and ROMS are global variables seen by all. //individual Serial #s and readings #define DEVICES 4 int ROMS[DEVICES][8]; int TEMPS[DEVICES]; int GetTemperatures(int BASE) 1 of 6 050100

// init. the 1-Wire Master Initialize(BASE); // exit if no devices can be found if(reset(base)) return(1); APPLICATION NOTE 120 // find all individual Serial#s FindROMs(BASE); // Convert temp. and read devices ConvertT(BASE); ReadTemps(BASE); return(0); OPERATION The host begins by initializing the DS1WM for proper 1-Wire bus timing by writing to the Clock Divisor Register. The value for a 50 MHz clock input is 0x0Fh (see the DS1WM datasheet). The host initializes INTR line by writing 0x3Dh to the Interrupt Enable Register. This makes the INTR pin active low and generates interrupts on data transmitted and reset complete. void Initialize(int BASE) // Divide the clock outp(base+4,0x0f); // Generate INTs on reset and send outp(base+3,0x09); The host must then determine if there are any devices present on the 1-Wire bus. To do this it issues a reset by writing 0x01 to the Command Register and waits for an interrupt to be generated. Upon an interrupt, the host reads the Interrupt Register and verifies that a slave device generated a presence detect by reading bit 2 to be low. If bit 2 is high, the CPU determines there is a bus error or no devices present and takes appropriate action. The WaitforInterrupt() function is not defined in this paper. It is a way for the main program to accomplish other tasks while waiting and can be defined completely by the user. int Reset(int BASE) if(inp(base+2) & 0x02) return(1); //no presence found else return(0); //presence found The host must learn the individual ROM codes for each of the devices on the 1-Wire bus. This is accomplished by running a Search ROM algorithm. The host sends the Search ROM command to the slaves and places the 1-Wire Master in Search ROM Accelerator mode. The host transmits the 16 byte search value based on the last ROM value found. These 16 bytes are 0x00 for the first run. The 16 bytes returned contain the new ROM code and are also used to generate the next 16 bytes to transmit. 2 of 6

This process is repeated until serial numbers duplicate to find all devices. In this case it known that there are only four devices and since only enough memory has been allocated for four ROM codes, the loop is completed only four times. The RecoverROM function will generate the new data to transmit and extract the new ROM code from the data just received. It must be called once with a NULL pointer for the received data to initialize. The entire RecoverROM function is contained at the end of this application note. The Search ROM Accelerator process is described in detail in the DS1WM datasheet. int FindROMs(int BASE) int loop; int dev; int TData[16]; int RData[16]; // reset RecoverROM and generate the // starting TData RecoverROM(NULL,TData,NULL); //run once for each device for(dev=0;dev<4;dev++) outp(base+1,0xf0); // send SeachROM // enter Accelerator mode outp(base,0x01); // transmit the TDATA and receive // the RDATA. for(loop=0;loop<16;loop++) outp(base+1,tdata[loop]); inp(base+1,rdata[loop]); //decode recovered ROM and generate //next Search value RecoverROM(RDATA,TData,ROMS[dev]); The unique serial numbers found will be used later to read out individual data from the slave devices. They are not needed to write a global command to all devices. The host orders all slaves to perform a temperature conversion by writing 0x44h. This command can be sent to all four devices simultaneously by following the skip ROM command, 0xCC, directly after a bus reset. int ConvertT(int BASE) outp(base+1,0xcc); // skip ROM outp(base+1,0x44); // convert Temp. 3 of 6

s convert temperature fast enough that no wait time is necessary. The host must now individually address each device to read its temperature value. After resetting the bus, the host issues a Match ROM command followed by the 64-bit serial number then a Read Scratchpad command. The host then reads 2 bytes of temperature data. Remember, to read data on the 1-Wire bus, the host must transmit 0xFFh first. The 2 bytes of data are then combined to produce the complete 16 bit temperature value. This process is repeated for each device. int ReadTemps(int BASE) int dev,loop; int LSB,MSB; for(dev=0;dev<4;dev++) outp(base+1,0x55); // match ROM // send 8 bytes of ROM code for(loop=0;loop<8;loop++) outp(base+1,roms[dev][loop]); outp(base+1,0xbe); // read memory outp(base+1,0xff); // read LSB LSB = inp(base+1); outp(base+1,0xff); // read MSB MSB = inp(base+1); TEMPS[dev] = MSB<<8 + LSB; The process is now complete. GetTemperatures has either returned 1 signaling no devices were found on the bus, or it updated ROMS and TEMPS with the values found from each of the four devices. If the devices ROM codes were known ahead of time the entire Search ROM process could have been skipped. If there was only one device on the bus, its serial number does not need to be known, a Skip ROM command could have been used for every transaction. If no interrupt line is available, the WaitforInterrupt function could be written to poll the Interrupt Register for command completion. This action, however, ties up the CPU waiting for the 1-Wire Master to finish its operation. 4 of 6

RecoverROM SOURCE CODE The source code provided on the following two pages can be included in the user s code to generate the 16 byte transmit values and extract the latest ROM code from the 16 byte received values during the Search ROM process. The function requires pointers to a 16 byte receive data array, a 16 transmit data array (which it will write to), and an 8-byte ROM code array (which it will also write to). The function returns a 0 if there are still unknown devices on the 1-Wire bus or 1 if all devices on the bus have been found. This feature was not used in the above example. This function has no error checking. If used in a condition where no devices are present, the ROM codes found will be incorrect. ///////////////////////////////////////////////////////////////////////////////// // RecoverROM performs two functions. Given 16 bytes of receive data taken from // the 1-Wire Master during a Search ROM function, it will extract the ROM code // found into an 8 byte array and it will generate the next 16 bytes to be trans- // mitted during the next Search ROM. // RecoverROM must be initialized by sending a NULL pointer in ReceivedData. It // will write 16 bytes of zeros into TransmitData and clear the discrepancy tree. // The discrepancy tree keeps track of which ROM discrepancies have already been // explored. // RecoverROM also returns a value telling whether there are any more ROM codes to // be found. If a zero is returned, there are still discrepancies. If a one is // returned all ROMs on the bus have been found. Running RecoverROM again in this // case will result in repeating ROM codes already found //////////////////////////////////////////////////////////////////////////////// int RecoverROM(int* ReceiveData, int* TransmitData, int* ROMCode) int loop; int result; int TROM[64]; // the transmit value being generated int RROM[64]; // the ROM recovered from the received data int RDIS[64]; // the discrepancy bits in the received data static int TREE[64]; // used to keep track of which discrepancy bits have // already been flipped. // If receivedata is NULL, this is the first run. Transmit data should be all // zeros, and the discrepancy tree must also be reset. if(receivedata == NULL) for(loop = 0; loop < 64; loop++) TREE[loop] = 0; for(loop = 0; loop < 16; loop++) TransmitData[loop] = 0; return 1; // de-interleave the received data into the new ROM code and the discrepancy bits for(loop = 0; loop < 16; loop++) if((receivedata[loop] & 0x02) == 0x00) RROM[loop*4] = 0; else RROM[loop*4 ] = 1; if((receivedata[loop] & 0x08) == 0x00) RROM[loop*4+1] = 0; else RROM[loop*4+1] = 1; if((receivedata[loop] & 0x20) == 0x00) RROM[loop*4+2] = 0; else RROM[loop*4+2] = 1; if((receivedata[loop] & 0x80) == 0x00) RROM[loop*4+3] = 0; else RROM[loop*4+3] = 1; if((receivedata[loop] & 0x01) == 0x00) RDIS[loop*4] = 0; else RDIS[loop*4 ] = 1; if((receivedata[loop] & 0x04) == 0x00) RDIS[loop*4+1] = 0; else RDIS[loop*4+1] = 1; if((receivedata[loop] & 0x10) == 0x00) RDIS[loop*4+2] = 0; else RDIS[loop*4+2] = 1; if((receivedata[loop] & 0x40) == 0x00) RDIS[loop*4+3] = 0; else RDIS[loop*4+3] = 1; // initialize the transmit ROM to the recovered ROM for(loop = 0; loop < 64; loop++) TROM[loop] = RROM[loop]; // work through the new transmit ROM backwards setting every bit to 0 until the 5 of 6

// most significant discrepancy bit which has not yet been flipped is found. // The transmit ROM bit at that location must be flipped. for(loop = 63; loop >= 0; loop--) // This is a new discrepancy bit. Set the indicator in the tree, flip the // transmit bit, and then break from the loop. if((tree[loop] == 0) && (RDIS[loop] == 1) && (TROM[loop] == 0)) TREE[loop] = 1; TROM[loop] = 1; break; if((tree[loop] == 0) && (RDIS[loop] == 1) && (TROM[loop] == 1)) TREE[loop] = 1; TROM[loop] = 0; break; // This bit has already been flipped, remove it from the tree and continue // setting the transmit bits to zero. if((tree[loop] == 1) && (RDIS[loop] == 1)) TREE[loop] = 0; TROM[loop] = 0; result = loop; // if loop made it to -1, there are no more discrepancy bits // and the search can end. // Convert the individual transmit ROM bit into a 16 byte format // every other bit is don't care. for(loop = 0; loop < 16; loop++) TransmitData[loop] = (TROM[loop*4]<<1) + (TROM[loop*4+1]<<3) + (TROM[loop*4+2]<<5) + (TROM[loop*4+3]<<7); // Convert the individual recovered ROM bits into an 8 byte format for(loop = 0; loop < 8; loop++) ROMCode[loop] = (RROM[loop*8]) + (RROM[loop*8+1]<<1) + (RROM[loop*8+2]<<2) + (RROM[loop*8+3]<<3) + (RROM[loop*8+4]<<4) + (RROM[loop*8+5]<<5) + (RROM[loop*8+6]<<6) + (RROM[loop*8+7]<<7); if(result == -1) return 1; return 0; // else continue // There are no DIS bits that haven't been flipped // Tell the main loop the seach is over REFERENCES: [1] Book of ibutton Standards, Dallas Semiconductor, online at http://www.ibutton.com/ibuttons/standard.pdf [2] DS1WM Datasheet, Dallas Semiconductor, online at http://www.dalsemi.com/doccontrol/pdfs/1wm.pdf [3] Datasheet, Dallas Semiconductor, online at http://www.dalsemi.com/doccontrol/pdfs/18b20.pdf [4] Application Note 119 Embedding the 1-Wire Master, Dallas Semiconductor, online at http://www.dalsemi.com/doccontrol/pdfs/app119.pdf 6 of 6