VTI Instruments Corp.
326
EX1629 Onboard Memory
for (i = 0; i < ((2*DS2430_SCRATCHPAD_LEN) +
(DS2430_SCRATCHPAD_LEN-1)); i+=3)
{
strncpy(byte, &data[i],2);
SendPkt[+] = (uint8_t)strtoul(byte, NULL, 16); //convert
to hex
}
// request the result buffer as the last command
SendPkt[+] = CMD_GETBUF;
// set the length
SendPkt[0] = sendLen - 1;
// send and receive the frame
MLanHostPacketSend(SendPkt, channel);
recLen = MLanHostPacketReceive(RecPkt, channel, MLAN_PACKET_SIZE);
return recLen;
}
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.
Содержание EX1629
Страница 310: ...VTI Instruments Corp 310 EX1629 Command Set...
Страница 342: ...VTI Instruments Corp 342 EX1629 Onboard Memory...