Dallas: Using The Serial Port

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

APPLICATION NOTE

DALLAS Programming DS243x Battery Instrumentation Chips


SEMICONDUCTOR

Dallas Semiconductor’s Battery Instrumentation chips 2. USING THE SERIAL PORT


allow storage of non-volatile information, such as 2.1 WITHOUT A DS2480 1-WIRE BUS-MASTER
manufacturing data, battery parameters, and other
information pertinent to the battery pack each device is Application note #74 explains in great detail the hardware
being used with. Although Dallas offers a custom and mechanical interface to 1-wire devices. Dallas’ Battery
programming for quantities of 5k pcs. or larger, the Instrumentation IC’s use a sub-set of the microLAN standard,
following note explains which alternatives are available to which means, that they use the same communication protocol
run prototypes, or small production lots. Using the 1-wire (transport layer), but differ with microLAN features, such as
communication protocol, it is possible to program multiple addressability (network layer), overdrive, and
devices simultaneously without data conflict. Verification, programmability. Due to the nature of a limited battery pack
however, may require the addition of a DS2407 supply voltage, non-volatile data is stored by using internal
addressable switch to isolate each individual device. This charge pumps - rather than applying external 12V pulses.
is necessary for DS2434 and DS2435 chips because these
chips do not use the 64 bit identification code. Figure 1 display a typical hardware interface, which is used in
our DS3701 Com-Port adapter:
There are five programming possibilities:

1. Demonstration kit
2. Serial port interface with or without a DS2480
3. Parallel port interface using a DS1481 bus-master
4. Standalone micro-controller
5. Custom pre-programmed part from Dallas

Here are the pros and cons:


Figure 1: Com-Port adapter schematic
1. THE DEMONSTRATION KITS
The 1-wire protocol timing specifications require that the
The DS2434 and DS2435 demonstration kits are, as the name serial port is able to communicate at 115k baud. Because the
suggests, demonstration kits. The programming option is 1-wire GND terminal has to remain the voltage reference, the
fully functional, however, for more than a few prototypes, it is ordinary DS9097 com-port adapter cannot be used. During
not only inefficient but will quickly reduce programming programming, supply 5V to the DS243x, which the DS3701
yields over time. This is due to the socket wearing out fast, derives from the RS-232 line voltages. For the use with serial
since it is designed for non-repeating insertions. Although ports slower than 115kbps, a DS2480 has to interface between
source code can be obtained from Dallas Semiconductor, it is the serial port and the 1-wire devices. This circuit is outlined
advised to use these kits for demonstration or proof-of- in the following paragraph.
concept prototypes only. They work under Windows 3.x or
95. Printed circuit board modifications are required for the
use of a TO-92 style - or 16 pin SSOP - socket.

ADVANCE INFORMATION: NHW 09/15/97 9:56 AM PG 1


SUBJECT TO CHANGE AT ANY TIME WITHOUT NOTICE
2.2 WITH A DS2480 1-WIRE BUS-MASTER 3. DS1481 PARALLEL PORT INTERFACE
This chip is an RS-232-to-1-wire bus-master. It’s NMI interrupts of the PC will not guarantee flawless
communication speed is programmable from 9,600 baud communication to a 1-wire device through a parallel port
(default) to 115k baud, and releases the PC from timing directly, and is discouraged to attempt. As the 1-wire protocol
constraints. The DS2480 interfaces directly to the serial port requires the first 15us of each time slot to contain the data
and receives the exact commands that are directed to the 1- information, any disruption of this time segment will result in
wire device. Then it converts the data byte into a 1-wire bit a communication error. Communicating through the PC
stream, or buffers the incoming bit stream until the serial port parallel port, as it has been utilized for Dallas Thermal Demo
is ready to receive the data. This simplifies the programmer kits DS1820K and DS1821K, requires timing corrections.
development to raw data exchange without timing overhead These functions are performed by the DS1481 bus-master. It
and restrictions. As Dallas’ software development kit translates code from the parallel port to the 1-wire data line,
DS0621-SDK may be already at hand, fundamental “Touch” - and buffers data coming from the 1-wire device to the parallel
I/O commands can be used to build the transport layer: port:
This boilss down the the two functions Touch_Reset, and
TouchByte, as the 1-wire bus can only assume one of the
following six states:
RESET, PRESENCE, WRITE_0, WRITE_1, READ_0,
AND READ_1. The idle state should always be logic high.
However, the entire kit, with its overhead of iButton
functions, is overkill for such a project. Figure 2 depicts a
typical schematic for the interface:

Figure 3: Parallel port adapter as used with the DS1820K.

Programming through the parallel port may seem complex,


but it still is a useful alternative when no serial port is
available. Power can be supplied through the parallel port,
which is often referred to as “parasite power”. Schottky
diodes feed current into a 22uF storage capacitor.

Figure 2: Com Port adapter with DS2480 bus-master

Programming more than one device at a time requires a


stronger power supply than the supply through the serial port
will provide. Although pin 1 of the RJ-11 connector provides
5V through a low drop-out linear voltage regulator, consider
an external power supply for supporting multiple devices.
This applies to gang-programmers, as the write process to
EEPROM plus drive current for the (optional) LED’s will
consume considerable power (see figure 4).

ADVANCE INFORMATION: NHW 09/15/97 9:56 AM PG 2


SUBJECT TO CHANGE AT ANY TIME WITHOUT NOTICE
4. STANDALONE MICRO-CONTROLLER HARDWARE INTERFACE
The function of a DS2480 can be entirely emulated with a While the next generation DS2436 and DS2437 utilize their
microcontroller. Source code patches for the following unique 64 bit ID code to allow only one device at a time to
processors are available: talk to the 1-wire master, the DS2434 and DS2435 need a
a) Intel 8051 and derivatives, DS2407 addressable switch to facilitate communication.
b) Motorola 68HCxx,
c) Microchip PIC series,
d) Hitachi 6303.

This source code enables a 1-wire bit stream and covers all
fundamental six states of the 1-wire data line:
1. Reset
2. Presence
3. Write_0
4. Write_1
5. Read_0
6. Read_1

All commands will use these six functions as sub-routines,


since the sequence of a 1-wire protocol is given:
1. RESET,
2. PRESENCE (detect),
3. ROM command plus data - identifies a 1-wire device,
4. function command plus data (receive or transmit).

While the two previous programmer solutions are using a


“bus-master“ for correct timing, this approach must pay Figure 4: Hardware interface for programming DS2434
attention to the protocol standards. During bit transmissions,
do not allow interrupts. In between two bit transmissions, the Switch PIO-B connects the GND connection of the DS2434,
idle state of the 1-wire is high and interrupts may be serviced. similar to the branching technique explained in application
Unless a RESET is issued, which resets the internal data note #106. When the internal FET is turned on, the DS2434
pointer of the 1-wire state-machine, the protocol picks up can read from the DQ line and receive or transmit data. PIO-
where it left off. B is used to send a visual alert when device programming
failed. Thus it is easy to physically locate the faulty unit on
the gang programmer board. Since all outputs are open drain,
5. CUSTOM PART a 10k pull-up resistor pulls the gate of the external p-channel
FET high (in-active), turning the LED off.
A pre-programmed chip will solve the needs for developing
and maintaining a 1-wire programmer. Additionally, there Because twenty or more LED’s can consume significant
will be no yield loss, because programming occurs at the current, consider a PCB layout that uses a star-type current
factory. Dallas Semiconductor requires a minimum order of return path. Having the high current return separated from
5,000 pieces for any custom Battery Management IC. A non- the low current GND reference of the DS2407 will promote
recurring engineering charge (NRE) charge may apply in safer communication due to increased logic low level
addition to a small adder on top of the standard component margins.
cost.

ADVANCE INFORMATION: NHW 09/15/97 9:56 AM PG 3


SUBJECT TO CHANGE AT ANY TIME WITHOUT NOTICE
PROGRAMMING THE SOFTWARE PROGRAMMING WITH A DS2480 BUS MASTER

Using the addressable switches to program 20, 30, or even 50 The DS2480 supports 1-wire communication through the
battery instrumentation IC’s is most simple because all PIO-B serial port - at any baud rate. Its design incorporates a
switches can be turned on at the same time. The verification “SEARCH Accelerator”,. This feature increases the speed to
process, however, requires that only one PIO-B switch is find all participating 1-wire devices on the bus from about 40
turned on at a time. This will prevent data collision when the to about 180 devices per second. Since all participating
battery instrumentation IC is talking back to the 1-wire bus devices are of the same family, a significant amount of this
master. First of all, before any devices can be programmed, address remains constant and helps finding the remaining
each DS2407 has to be polled for their unique address code addresses more quickly:
with the SEARCH_ROM command. Note, that at this time all On command, the DS2480 receives and retrieves 16 nibbles
DS243x devices are disconnected from the bus. The LSB first of actual ROM address and sixteen nibbles of a verifier called
protocol then executes three read time slots to retrieve one bit “discrepancy bit” - here: D-bit. These 16 bytes make up two
at a time , with the following syntax: sets of eight bytes, which then have the following structure:

1. read Bit_0 of all devices, 7 6 5 4 3 2 1 0


2. read the inverse bit_0 of all devices, R3 D3 R2 D2 R1 D1 R0 D0
3. write either ‘1’ or ‘0’, depending on the outcome of steps
one and two:
Table 2: Search Accelerator byte (LSB) - one out of sixteen
1st read 2nd read result
0 0 devices with bit_x = 0 AND devices After the data mode of the DS2480 has been selected with
with bit_x =1 are connected to the [E1h], send 16 bytes to determine the logical decision path in
bus. the event of a logical conflict. This occurs, when either logic
0 1 all devices connected to the bus have value of the same address bit is present on the bus. Because
bit_x = 0 the D-bits are not encountered during a write process to the
1 0 all devices connected to the bus have DS2480, these bits are DON’T CARE terms. They will
bit_x = 1 indicate
1 1 not valid - Start to perform a Search ROM sequence with all bits Rn
check for software/hardware errors being 0’s. The returned bytes will flag the exact bits of the 64
bit address, which contain both, logic 1 and logic 0 states.
Table 1: SEARCH_ROM results for each bit of the 64 bit ID.
Bit no. 7 6 5 4 3 2 1 0
During the third time slot, the DS2407 is reading type R D R D R D R D
information: it turns itself off if this bit is not equal to its ID shift-R 7 6 5 4 3 2 1 0
bit. It stays on-line, if this ID bit equals the third time slot div. by 128 64 32 16 8 4 2 1
(write cycle). If devices with either bit state are present, you ROM R3 R2 R1 R0
need to select one state and, after completion of this ID D-BIT D3 D2 D1 D0
branch, repeat the procedure with the opposite bit logic state.
This bit screening routine is performed for each one of the 64 Table 3: Unwrap nibbles from tLastReceived of the DS2480
bits. Once each DS2407 has been identified, either store this
information in NV memory, or make this procedure part of The first byte will contains the lower nibble, the second byte
the power-up routine for the programmer. The microLAN will contain the higher nibble of the ROM code.
protocol allows to find about 70 devices per second. Repeat this process until you find the highest number D-bit.
Since each process starts with determining the address in the
You can broadcast programming data to all the DS243x at the event of a discrepancy, the selection will branch out form the
same time, provided all PIO-B switches are turned on. Then higher address to the lower address. This recursive iteration,
turn all switches off, and turn one at a time back on, using the is illustrated in figure 5:
MATCH_ROM command. Verify programming of the
DS243x and when unsuccessful, either retry programming or
turn on the LED through PIO-A of the same DS2407 for
visual indication.

ADVANCE INFORMATION: NHW 09/15/97 9:56 AM PG 4


SUBJECT TO CHANGE AT ANY TIME WITHOUT NOTICE
Figure 5: Using the Search_ROM function with a DS2480 bus-master. This flowchart illustrate how to perform the
Search_ROM function using the Search
ROM Accelerator of the DS2480. The notes
below follow along with the flowchart to the
left. If in Command Mode, the DS2480 will
send a RESET to the 1-wire port, and return
either [C5 h] or [E5 h] when at least one 1-
wire device has been recognized.

When turning the accelerator ON, discard


the echo of [F0 h], which the DS2480
produces when searching for 1-wire
devices.

This routine checks for the highest order


discrepancy bit that is flagged (logic high).
Note, that all 1-wire communication is LSB
first.

TCurrDiscNum is the current discrepancy


number. Perform the discrepancy test with a
logic AND function with 55 h. This screens
out all ROM code bits and retrieves all
discrepancy bits from the code received
from the DS2480.

This inner loop is repeated for all 16 bytes,


which contain the 8 byte ROM code and the
discrepancy bits for each bit location. Build
a discrepancy history by selecting first all
“zero” addressed devices - then continue
with all devices containing a “one” in that
flagged location.

(*) If there is no discrepancy at all, but a 1-


wire device has signaled presence to the
DS2480, obviously there only one device on
the bus.

“Unwrap” the nibbles of each ROM-Byte


into ROM code and discrepancy bits.
Note, that each byte contains a nibble for
the ROM code and a nibble for the
discrepancy bits. Consequently, the first
byte [j] contains the lower nibble and is
shifted right. The second byte [j+1] contains
the higher nibble, and is shifted left.
Eventually, all eight bytes are OR-ed to
yield the ROM code for the particular
device. These functions are easily
implemented in a “C” based language, since
it “C” support bit manipulation functions
such as SHIFT RIGHT (>>), SHIFT LEFT
(<<), logic AND (&) and logic OR (|).

ADVANCE INFORMATION: NHW 09/15/97 9:56 AM PG 5


SUBJECT TO CHANGE AT ANY TIME WITHOUT NOTICE
ADVANCE INFORMATION: NHW 09/15/97 9:56 AM PG 6
SUBJECT TO CHANGE AT ANY TIME WITHOUT NOTICE

You might also like