Hi,
I don't understand.... Your example will only send one byte (because the SHIFTOUT is outside of the FOR-NEXT loop), mine will send as many bytes as you set num_byte to (plus one). If you load your array with 12 values (0-11) and then set Num_byte to 11 before calling SPI_Write it will SHIFTOUT 12 bytes. It iterates thru the loop and copies the value from array pointed to by x into the temporary variable which it then uses to send that particular byte.
Do you mean that you actually need to send a comma (ASCII 44) between each databyte? I don't think that's what you mean but IF so then perhaps something like this will work
Code:
SPI_write:
CS = 0 ' Chip enable
For x = 0 to Num_byte ' loop for # byte
temp_data_out = data_out(x)
Shiftout SI, SCK, MSBFIRST, [temp_data_out] ' Send byte
' Send a comma after the byte. EXCEPT for the last byte.
If x < Num_byte THEN
Shiftout SI, SCK, MSBFIRST, [","] ' Or perhaps LSBFIRST here
ENDIF
next x
CS = 1 ' Disable to execute command
return
Now, when Num_Byte is 5 and you GOSUB SPI_Write the CS line will go low, then it will send the first value in the array ( Data_out(0) ) followed by a comma. Then it will send Data_out(1) followed by a comma and so on. When it sends the last databyte ( Data_out(Num_byte) ) the x variable is no longer less than Num_Byte so this time it won't send the comma.
But again, I have a feeling I'm missunderstanding...
/Henrik.
Bookmarks