Shop OBEX P1 Docs P2 Docs Learn Events
Using BASIC stamp to access SD via SPI — Parallax Forums

Using BASIC stamp to access SD via SPI

bunnibunni Posts: 38
edited 2009-03-19 19:17 in BASIC Stamp
Hello,

This is the dilemma I am currently in. I am working on a team at the University of Advancing Technology to launch a nearspace balloon, we had everything ready to go, sensors, radios, etc. We were going to use the radio to send positional data as well as voltage and internal temperature, all other sensors were just going to record data on an SD card. We had the very handy sparkfun MicroSD device ordered so we could just send serial data from the stamp and have it be recorded. The device is on backorder for months and we are scheduled for launch on the 16th of August. Now we are forced to do all of the bit-banging ourselves. There was a thread a while back of someone getting communication working properly:

http://forums.parallax.com/forums/default.aspx?f=5&m=62712

I can't, I am stuck and need help. If anyone has code that they would be willing to post I would greatly appreciate it. Either way, here is my code:

' {$STAMP BS2p}
' {$PBASIC 2.5}

SDCLK PIN 14
MOSI PIN 15
MISO PIN 13

aword VAR Word
bword VAR Word
cword VAR Word
recv  VAR Byte

main:
OUTPUT SDCLK
OUTPUT MOSI
INPUT MISO
DEBUGIN HEX aword
DEBUGIN HEX bword
DEBUGIN HEX cword



SHIFTOUT MOSI, SDCLK, MSBFIRST, [noparse][[/noparse]aword\16, bword\16, cword\16]

SHIFTIN MISO,SDCLK,MSBPOST, [noparse][[/noparse]recv\8]

DEBUG HEX2 recv



GOTO main



This will just take in a few bytes (like 0x400000000095 to put the device in SPI mode) and shift them out and then shift the response back. I get nothing, it seems like it didnt even understand my transmission, there are no flickers on the MISO line.

I have switching MOSFETs for MOSI and SDCLK, those show up fine on my o-scope and at the correct voltage levels, just no response back.

Thank you to anyone that can offer advice.

-Bunni

Comments

  • DufferDuffer Posts: 374
    edited 2008-07-30 23:42
    bunni, I may be able to help. Sent you a PM.
  • bunnibunni Posts: 38
    edited 2008-07-31 02:58
    Thank you for the help Duffer.

    I would still like to know if anyone has a BASIC code example for communicating with an SD card, just to solve me original issue. I hate leaving open ends when I start a project.

    -bunni
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-31 03:25
    I would suggest you don't wait for someone to show up with examples. The Stamps have too little memory and are too slow for direct SD control to be practical, particularly with the 512 byte block size. There are several external devices for writing to an SD card or MMC card similar to what SparkFun has for sale. Hitt Consulting sells an SD card datalogger that's small and low power (www.hittconsulting.com/) and comes with sample code. Parallax also sells a USB memory stick datalogger with examples of its use with Basic Stamps. Depending on the amount of data involved, you might be able to just save the data to the BS2p's extra EEPROM slots using the STORE / READ / WRITE statements. The BS2p has 7 extra "slots", each 2K that you probably are not using already for a total of 14K. The BS2pe is a slightly slower, slightly lower power drain Stamp with a total of 16 2K "slots". The last 8 are only for data storage giving you a total of 30K beyond the first 2K used for programming. As several people have mentioned in the thread you referenced, it's very easy to add additional EEPROM. If you use the Atmel 24C1024B, you can trivially add four to a pair of I/O pins for a total of 512K bytes of easy to use storage. With the BS2p, you have built-in I2C statements that makes the use of these EEPROMs very simple.
  • peachmanpeachman Posts: 1
    edited 2009-03-19 19:17
    I know its been awhile since this post has been read but I have a similar question as the original poster.

    Unfortunately, I don't have the hitt consulting data logger. Instead, I have this:

    http://store.gravitech.us/micaad.html

    It does not come with a manual, unfortunately.

    Is it possible to send about 5 values per minute to this microSD card using this adapter and a BS2?

    Thanks,
    Jeff
Sign In or Register to comment.