Shop OBEX P1 Docs P2 Docs Learn Events
Memory Stick SPI with BS2 code — Parallax Forums

Memory Stick SPI with BS2 code

dpulgardpulgar Posts: 4
edited 2012-03-19 15:08 in BASIC Stamp
I need an example in relation to Memory Stick #27937,
must contain at least one example for BS2 SPI communication,
I have seen a library for the propeller. But the truth is that not understand spin.

I need at least the initial code in BS2 with SPI.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-01-06 15:34
    I don't think you'll find any examples of SPI communications with the Memory Stick Datalogger and a BS2. Serial is much easier and there are examples of that available from Parallax. Attached is the datasheet for another implementation of the Vinculum USB Host chip used in the Datalogger. The description of the SPI interface timing starts roughly on page 9. Notice that the data exchange involves 11 bits, 3 with control information and 8 with data. You'd need to use the HIGH and LOW statements to control CS and the SHIFTOUT and SHIFTIN statements for the clock and data lines. If you read the chapters on the SHIFTOUT and SHIFTIN statements in the Stamp Basic manual, you'll see that you can specify the number of bits (up to 8), so you can use a SHIFTOUT statement for the 3 control bits, then either a SHIFTOUT or SHIFTIN statement for the 8 data bits.

    The data transfer using SPI is going to be very much slower than using serial I/O. I don't recommend it for the Stamps.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-01-07 20:13
    The SPI mode doesn’t allow the BASIC Stamp to use any formatters on the data input/output. Because of this, serial is the better choice. It’s not that we’re lacking example code for the Datalogger but rather that we’ve allowed features of the Vinculum chip to be brought out that not every microcontroller will make use of. In all fairness the Vinculum also supports a parallel mode, but that isn’t supported by this module and this is really designed for high-speed transfers anyway. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • TWRackersTWRackers Posts: 33
    edited 2009-01-08 04:32
    Mike Green said...
    I don't think you'll find any examples of SPI communications with the Memory Stick Datalogger and a BS2. Serial is much easier and there are examples of that available from Parallax. Attached is the datasheet for another implementation of the Vinculum USB Host chip used in the Datalogger. The description of the SPI interface timing starts roughly on page 9. Notice that the data exchange involves 11 bits, 3 with control information and 8 with data. You'd need to use the HIGH and LOW statements to control CS and the SHIFTOUT and SHIFTIN statements for the clock and data lines. If you read the chapters on the SHIFTOUT and SHIFTIN statements in the Stamp Basic manual, you'll see that you can specify the number of bits (up to 8), so you can use a SHIFTOUT statement for the 3 control bits, then either a SHIFTOUT or SHIFTIN statement for the 8 data bits.

    The data transfer using SPI is going to be very much slower than using serial I/O. I don't recommend it for the Stamps.
    I've succeeded in getting my BS2sx to talk to my Datalogger in SPI mode. In my application I'm writing a fixed-record-length file in binary, so formatters aren't necessary. I'm able to write 9-byte records at 10 records/sec, which is all I need. Why do you say that SPI is slower than serial?

    While I'm at it, there's a 3-pin header on the component side of the Datalogger mounted parallel to the long dimension of the board, but its purpose isn't documented. What's that for?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-01-08 04:49
    The SPI mode requires 11 bits per byte of data and the bytes have to be sent individually. You can string several bytes together in one SHIFTOUT, but you can't do input that way (because you need a SHIFTOUT for the 3 control bits, then a SHIFTIN for the 8 data bits). As Chris mentioned, you can't use the Basic formatters as you can with SEROUT so that slows down the actual data rate.
  • TWRackersTWRackers Posts: 33
    edited 2009-01-08 05:06
    Mike Green said...
    The SPI mode requires 11 bits per byte of data and the bytes have to be sent individually. You can string several bytes together in one SHIFTOUT, but you can't do input that way (because you need a SHIFTOUT for the 3 control bits, then a SHIFTIN for the 8 data bits). As Chris mentioned, you can't use the Basic formatters as you can with SEROUT so that slows down the actual data rate.

    Well, fortunately SPI is fast enough for my particular application (reading the H48C 3-axis accelerometer 10x per second and writing the data in binary to a file), so I can just stick with that. Besides, the Datalogger in SPI mode and the accelerometer device can share most of their pins, except for the two Chip Select lines. And the Datalogger in SPI mode can use the same Stamp pin for SDI and SDO just like the H48C does. May not be the fastest solution, but it's fast enough for what I need.
  • jimbobandersonjimbobanderson Posts: 3
    edited 2012-03-19 15:08
    Would you be so kind as to share your code. I am also interested in SPI interface for the DataLogger.
    TWRackers wrote: »
    I've succeeded in getting my BS2sx to talk to my Datalogger in SPI mode. In my application I'm writing a fixed-record-length file in binary, so formatters aren't necessary. I'm able to write 9-byte records at 10 records/sec, which is all I need. Why do you say that SPI is slower than serial?

    While I'm at it, there's a 3-pin header on the component side of the Datalogger mounted parallel to the long dimension of the board, but its purpose isn't documented. What's that for?
Sign In or Register to comment.