EasyManua.ls Logo

VTI Instruments EX1629 - Write_And_Copy_Scratchpad_2430

Default Icon
346 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
VTI Instruments Corp.
330 EX1629 Onboard Memory
Here is an example output from the READ_MEMORY command using the example code:
sent packet without errors
Packet length: 8
07 82 0A 03 22 F0 00 85
got a packet without errors on receive
Packet length: 39
26 82 00 0A 22 F0 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 the same string that was in the WRITE_SCRATCHPAD, now has been transferred into
non-volatile memory.
WRITE_AND_COPY_SCRATCHPAD_2430
As noted above, the scratchpad is a volatile memory location. Between MLAN commands, the
1-Wire devices are powered down, and, hence, will lose all their scratchpad (volatile) data. In
example code below, the commands occur fast enough that power is not lost to the 1-Wire devices
and no data loss is experienced. This, however, is not recommended for a production environment.
As a consequence, the WRITE_AND_COPY command set is recommended. These commands are
atomic operations they perform the write and the copy in a single MLAN command. Because the
read and write is accomplished in a single command, data integrity cannot be verified before it is
copied to memory (e.g. a READ_SCRATCHPAD command cannot be performed in the middle of
a WRITE_AND_COPY command set to verify the scratchpad write). However, the main memory
can still be checked after the write, in a separate series of MLAN operations to ensure that what
was written is correct.
int write_and_copy_scratchpad_2430(const char* data, int channel)
{
int sendLen, recLen = 0;
int i = 0;
char byte[3];
if(strlen(data) != ((DS2430_SCRATCHPAD_LEN * 2 ) +
(DS2430_SCRATCHPAD_LEN-1)))
{
printf("Data was not the right length (wanted 95, got %i)\n",
strlen(data));
return -1;
}
sendLen = 1; // reserve first byte for length
// access the current device with address in DATA_ID
SendPkt[sendLen++] = CMD_ML_ACCESS;
// construct a block of communication to MicroLAN
SendPkt[sendLen++] = CMD_ML_DATA;
SendPkt[sendLen++] = 3+DS2430_SCRATCHPAD_LEN; // block length
SendPkt[sendLen++] = 4+DS2430_SCRATCHPAD_LEN; // data length
// send the write scratchpad command
SendPkt[sendLen++] = WRITE_SCRATCHPAD;
// send the address byte
SendPkt[sendLen++] = 0;
// the bytes of data to write
for (i = 0; i < ((2*DS2430_SCRATCHPAD_LEN) +
(DS2430_SCRATCHPAD_LEN-1)); i+=3)
{
strncpy(byte, &data[i],2);
byte[2] = '\0';
SendPkt[sendLen++] = (uint8_t)strtoul(byte, NULL, 16); //convert
to hex
}

Table of Contents

Related product manuals