Shop OBEX P1 Docs P2 Docs Learn Events
A Memory Stick Datalogger SPI Question? — Parallax Forums

A Memory Stick Datalogger SPI Question?

Capt. QuirkCapt. Quirk Posts: 872
edited 2007-11-17 08:41 in General Discussion
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·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-25 04:24
    There was an SPI test program for the Vinculum VDIP (same chip as datalogger) that I posted some time ago. Here's the link:
    http://forums.parallax.com/showthread.php?p=620161
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-08-25 05:29
    After reading your .Spin code, it seems like I should use LSBPOST in my program. You also used a pin for EOL, can I do the same thing with the Parallax Datalogger, instead of sending (cr) at the end of each command?, possibly pin #6 (CTS)



    Thanks for the start. ·I am writing a program for my BS2P-40 first, then my SX.

    Bill
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-08-25 05:38
    There is an awful lot of pause statements in the UART version and I noticed your .spin program only had a 1/4 sec delay for initialization. Do you think I can get away without any further delays with the stamp?

    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.
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-08-26 18:16
    Here is the latest data sheet and a SPI,·Pic Boost C example program

    Post Edited (Capt. Quirk) : 8/26/2007 6:22:07 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-26 19:09
    The nice thing with SPI is that it's clocked. If you don't ask for data, nothing is sent (it's all buffered in the Vinculum until its buffer fills up). Each byte transferred requires 12 bits and you have to generate a clock before selecting the device and one after deselecting it. You can use a PULSOUT for that purpose. With SPI, the only pause would have to be one for initialization. If you try to use serial on a Stamp, you will have unanticipated delays waiting for serial data.

    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.
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-08-28 02:10
    Mike,

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-28 03:33
    You use SHIFTOUT for transfers to the logger and SHIFTIN for transfers from the logger. The Stamp produces the clock in both cases. According to the manual, the clock pin gets set to output mode (as it should be). I think you should set it yourself to output mode before you do the chip select. That avoids having the clock indeterminate because it's in input mode.

    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.
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-08-28 05:54
    Thanks Mike,

    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
  • dpulgardpulgar Posts: 4
    edited 2007-09-20 00:27
    I am trying to communicate the Memory Stick with BS2P in SPI mode but I can’t initialize it, in mode UART works fine but I prefer to work in SPI, somebody can help me.

    '
    [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
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-11-17 08:41
    Have you solved the issue?
    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
Sign In or Register to comment.