Informal Notes on the SPICommand()

I now think I have a better handle on the SPICmd.  For the life of me, I
couldn't see how the SPICmd could distinguish between sending x bytes and
then reading y bytes from that of sending x bytes while simultaneously
receiving y bytes.

In verbose terms one might define the SPICmd as;

   Call SPICmd(channel, 

For example, when dealing with a 25 series EEPROM; 

   Dim A(1 to 6) as Byte, Dummy as Byte

   ' enable write latch
   A(1) = WREN		' write enable command
   Call SPICmd(1, 1, A(1), 0, Dummy)
   ' send a single byte and then read 0 bytes into Dummy

   ' write a byte
   A(1) = WRITE		' write command
   A(2) = AddressHighByte
   A(3) = AddressLowByte
   A(4) = Dat

   Call SPICmd(1, 4, A(1), 0, Dummy)

Note that the following would work, but is dumb in this application;

   Call SPICmd(1, 3, A(1), 1, Dummy)

Note that four bytes are sent beginning at the address of A(1) and
continuing right along in sequence.  That is, the total of args 2 and 3.  
After three bytes are sent, one byte is read into dummy.  Of course, dummy
is garbage.

The following would work.  Again, its dumb.
   Call SPICmd(1, 2, A(1), 2, A(5))

Again, 4 bytes are sent.  After 2 are sent, the next 2 bytes are read into
A(5) and A(6).  Of course, they are garbage.

   ' read a byte
   A(1) = READ		' read command 
   A(2) = AddressHighByte
   A(3) = AddressLowByte

   Call SPICommand(1, 3, A(1), 1, A(4))

Note that 4 bytes are sent, but the 25256 ignores the 4th.  After, 3 bytes
are sent, 1 byte is read into A(4).

   Call SPICommand(1, 0, A(1), 4, A(1))

This will also work.  4 bytes are sent beginning at A(1) of which the
EEPROM uses only the first three.  After 0 bytes, 4 bytes are read into
the address space beginning at A(1).  The data in A(1), A(2) and A(3) is
garbage.  A(4) contains the value which is read from EEPROM.


With the TLC2543 11-ch 12-bit A/D, an 8 bit command is sent and at the
same time, 8 plus another 8 bits are received.


   A(1) = command
   Call SPICmd(1, 0, A(1), 2, A(2))

Note that two bytes are sent.  The TLC2543 only pays attention to the
first byte.  After no bytes (immediately), two bytes are read into A(2)
and A(3).  The break through for me was the recognition that arg 2 in the
SPICmd is the number of bytes to send prior to beginning to read the data
into the space at the GetData location.  The actual number of bytes sent
is the sum of args 2 and 4 in the SPICmd.

Thus, in reading 32 bytes from an EEPROM;

   Call SPICmd(1, 3, A(1), 32, B(1).

35 bytes are sent, beginning at A(1), but the EEPROM only reads the first
3.  After 3 are sent, the next 32 are read into the address space
beginning at array B.

Probably clear as mud!