VTI Instruments Corp.
328
EX1629 Onboard Memory
Here is some example output from READ_SCRATCHPAD using the example code:
sent packet without errors
Packet length: 8
07 82 0A 03 22 AA 00 85
got a packet without errors on receive
Packet length: 39
26 82 00 0A 22 AA 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
This is identical to what was written with the WRITE_SCRATCHPAD command, so the data was
written properly. Again, recall that the non-atomic operations cannot be guaranteed, as the 1-Wire
devices are powered down between MLAN commands, which erases the scratchpads.
COPY_SCRATCHPAD_2430
The COPY_SCRATCHPAD command is the only method for writing data to the memory of a
MLAN device; it copies the data in the scratchpad to the non-volatile memory. Like
READ_SCRATCHPAD, the command is fairly simple, as the data already exists and only needs
to be moved.
int copy_scratchpad_2430(int channel)
{
int sendLen, recLen = 0;
sendLen = 1; // reserve first byte for length
// access the current device with address in DATA_ID
SendPkt[+] = CMD_ML_ACCESS;
// construct a block of communication to MicroLAN
SendPkt[+] = CMD_ML_DATA;
SendPkt[+] = 3; // block length
SendPkt[+] = 2; // data length
// send the copy scratchpad command
SendPkt[+] = COPY_SCRATCHPAD;
// send the validation key
SendPkt[+] = 0xA5;
// delay for 128ms
SendPkt[+] = CMD_DELAY;
SendPkt[+] = 1;
SendPkt[+] = DELAY_128 | DELAY_MS;
// 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;
}
Once again, the first three bytes are the same as WRITE_SCRATCHPAD and
READ_SCRATCHPAD. Our block length is 3, as the expected response length, the
COPY_SCRATCHPAD command, and the “validation key” that ensures we are not writing to the
wrong device are sent. Each “family” of MLAN device has a different validation key. This will be
seen with the DS2431. Note that the expected response length is the minimum 2 bytes. Since the
COPY_SCRATCHPAD command does not actually return data to us, space does not have to be
allocated in the return buffer.