www.vtiinstruments.com
APPENDIX C
99
When the ASCII data format used in the example code is seen., the reason for the
(SCRATCHPAD_LEN * 2) + (SCRATCHPAD_LEN - 1)
code segment becomes more clear.
For the DS2430, a data string for the example code might look like this:
"01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18
19 1A 1B 1C 1D 1F 20 21"
For each hex byte, there are two characters (
LEN * 2
), plus one space for all but the last one (
LEN-
1
). This example code uses this format for easy parsing.
Once again, the first byte is reserved for the length of the packet, and then two very common MLAN
commands are sent, CMD_ML_ACCESS and CMD_ML_DATA. The ML_ACCESS command
allows the user to access a 1-wire device which was previously searched for and discovered.
ML_DATA tells the controller that data operations are going to begin on that device – that is, 1-
wire bus transactions will be performed.
The next command,
3+DS2430_SCRATCHPAD_LEN
, is actually the length of the command that
is being sent to the device. Since the entire scratchpad length is being written, that must be included.
Then, the
data length
block, the WRITE_SCRATCHPAD command itself, and the “0”, which
is the address in memory that the scratchpad will write to, must be added. Since data written to the
scratchpad will ultimately end up in the non-volatile memory, the target address in the non-volatile
memory must be provided when writing the data to the scratchpad. This provides a measure of error
detection, when the address is later provided in the copy scratchpad operation, as well as allowing
the device to return an error if the target memory is write-protected. The CMD_GETBUF is not part
of this block, as it is a separate command.
Note that data length block is 2+DS2430_SCRATCHPAD_LEN. The reason for this is that, when
writing to the scratchpad, the controller sends back what was written so that it can be verified. For
any MLAN command, two must be added to the length of the data that is expected to be returned
(for the command sent and command result to be returned), and the scratchpad data is the only data
we expect to be returned.
On the DS2430, address 0 is always written to after the WRITE_SCRATCHPAD command, as the
DS2430 scratchpad is the same size as the memory. Therefore, by writing a single scratchpad, the
entire memory will be overwritten. This will not always be the case, and, in fact, is not on the
DS2431, which will be seen later.
The “for” loop that is next in the code translates the ASCII text string “data”, which was passed in
(see the example data string above), into its hexadecimal equivalent to be sent to the controller.
The last command tells the controller to read back the result of the previous command. This is
invaluable, as it allows error codes to be viewed, if errors are returned. The last steps are to send the
completed packet and retrieve the response.
Here is how the output for a WRITE_SCRATCHPAD for the DS2430 looks when using the example
code:
sent packet without errors
Packet length: 40
27 82 0A 23 22 0F 00 AA 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11
12 13 14 15 16 17 18 19 1A 1B 1C 1D 1F 20 21 85
got a packet without errors on receive
Packet length: 39
26 82 00 0A 22 0F 00 AA 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11
12 13 14 15 16 17 18 19 1A 1B 1C 1D 1F 20 21
As can be seen, WRITE_SCRATCHPAD echoes the data written to it as well, which is why space
was allocated for it.
Содержание EMX-4016B
Страница 6: ......
Страница 7: ...www vtiinstruments com Introduction 7 ...
Страница 83: ...www vtiinstruments com APPENDIX B 83 Figure 4 429 EMX 4016B Break Out Box Figure 4 30 EMX 4016M Break Out Box ...
Страница 84: ...VTI Instruments Corp APPENDIX B 84 Figure 4 31 EMX4016B Outline Drawing Figure 4 32 Drawing Represent ...
Страница 116: ......