A Memory Stick Datalogger SPI Question?
![Capt. Quirk](https://forums.parallax.com/uploads/userpics/9JPOS4RYYPQ0/nAZVBWA800QOI.jpg)
I thought the use of SPI within the Parallax product languages was handled with Shiftin & Shiftout? Is there any SPI code examples for the DataLogger, or is·(asynchronous) serial with a handshake the same thing?
Thanks·
Bill·
Thanks·
Bill·
Comments
http://forums.parallax.com/showthread.php?p=620161
Thanks for the start. ·I am writing a program for my BS2P-40 first, then my SX.
Bill
I want to use it with either a servo(s) or·my PSC?. I·am·always concerned about the amount of PAUSE statements with any product, that is serial.
Post Edited (Capt. Quirk) : 8/26/2007 6:22:07 PM GMT
Pay attention to the description of the SPI transfer in the datasheet. The first 3 bits and the last bit are always sent to the Vinculum MSB first. The other 8 bits are data and are either received or transmitted by the Stamp, so you will always have to do a SHIFTOUT for the leading 1 bit, the read/write bit, and the status/data bit, then either a SHIFTOUT or a SHIFTIN for the data bits, then a single bit SHIFTOUT for the "retry" bit.
Since the data logger·is clocked, how do I use shiftin or shiftout for the data byte? Can I set the Cpin as an Input and not worry about Pbasic changing it back to an output?
Also, am I trying to use this device improperly?, I thought is·was intended to record data directly to the memstick. Or should I·record data·to an eeprom, and then to the memstick.
Thanks
Bill
You can certainly record data directly to the memory stick. You can also record it to EEPROM first, then copy it to a memory stick. It depends on what you want. EEPROM is predictable in terms of timing. It takes about 10ms per byte and the overhead is only the WRITE statement (and any bookkeeping to keep track of where). The data logger is a bit more unpredictable, but it's buffered so you can transfer a block of data relatively quickly, then it may take an unpredictable period of time to actually write it from the buffer. You can continue filling the buffer while the writing is going on.
I was confused by your statement about SPI being clocked. Since the Vinculum VDIP had a crystal, I thought the data logger provided the clock signal, instead of the Stamp or SX and·the Cpin was unnecessary for shiftin or shiftout to work.
Thanks for clearing that up for me.
Bill
'
[noparse][[/noparse] Program Description ]
'
[noparse][[/noparse] I/O Definitions ]
bs2_do PIN 8 ' SERIAL DATA INPUT --> 27937.4 (SDI)
bs2_cs PIN 9 ' CHIP SELECT --> 27937.6 (CS)
bs2_clk PIN 10 ' SERIAL CLOCK --> 27937.5 (SCLK)
bs2_di PIN 11 ' SERIAL DATA OUTPUT <-- 27937.2 (SDO)
'
[noparse][[/noparse] Constants ]
NumSamples CON 10 ' Number Of Samples To Log
Opcode_W CON %100
Opcode_R CON %110
'
[noparse][[/noparse] Variables ]
buffer VAR Byte(15) ' Input Buffer
index VAR Byte ' Index Variable
ioByte VAR Byte ' Input/Output Storage
flag VAR Bit ' Event Status Flag
'
[noparse][[/noparse] Initialization ]
DEBUG CLS
DEBUG "Memory Stick Datalogger Demo V1.0", CR
PAUSE 1000
DEBUG "Initializing...", CR
LOW bs2_clk
LOW bs2_do
LOW bs2_cs
PAUSE 2500 ' Allow Time To Settle
DEBUG "Done!", CR
DEBUG "Synchronizing...",CR
HIGH bs2_clk
LOW bs2_clk
HIGH bs2_cs
SHIFTOUT bs2_do,bs2_clk,MSBFIRST,[noparse][[/noparse]Opcode_W\3,"E"\9]
IF bs2_di = 1 THEN
DEBUG "NO ACCEPTED",CR
ELSE
DEBUG "ACCEPTED",CR
ENDIF
LOW bs2_cs
HIGH bs2_clk
LOW bs2_clk
HIGH bs2_clk
LOW bs2_clk
HIGH bs2_cs
SHIFTOUT bs2_do,bs2_clk,MSBFIRST,[noparse][[/noparse]Opcode_R\3]
SHIFTIN bs2_di,bs2_clk,MSBPOST,[noparse][[/noparse]ioByte,flag\1]
IF flag = 1 THEN
DEBUG "OLD DATA",CR
ELSE
DEBUG "NEW DATA",CR
ENDIF
DEBUG DEC3 ioByte,CR
LOW bs2_cs
HIGH bs2_clk
LOW bs2_clk
DO
LOOP
From the attached timing diagrams, it looks STATUS must be sampled after the rising edge of the
clock.
So perhaps
SHIFTOUT bs2_do,bs2_clk,MSBFIRST,[noparse][[/noparse]Opcode_W\3,"E"\9]
IF bs2_di = 1 THEN
DEBUG "NO ACCEPTED",CR
ELSE
DEBUG "ACCEPTED",CR
ENDIF
must be changed to
SHIFTOUT bs2_do,bs2_clk,MSBFIRST,[noparse][[/noparse]Opcode_W\3,"E"\8]
HIGH bs2_clk
IF bs2_di = 1 THEN
DEBUG "NO ACCEPTED",CR
ELSE
DEBUG "ACCEPTED",CR
ENDIF
LOW bs2_clk
If anyone has a working program for SPI mode, please post.
regards peter