Data Storage Tool Display Human Input Protocol Math Motor Control Sensor Signal Generation & Processing Speech & Sound Fun View all Objects


Quick Links
Contact Us
Forums
Support

Register
Login

This object is provided under license. By downloading this object, you are agreeing to the terms of the MIT License.

Datalogger SPI mode

Object for Parallax #27937 datalogger using SPI mode.
Bundled with test program that shows how to create
and remove directories and files. The object interfaces
to the device using 4 pins (cs,clk,din,dout).

Version:
  1.0

Type:
  Object

Attributes:


Author:
  Peter Verkaik

Categories:
  Data Storage

Downloads:
  2,820

Last Updated:
  2007-12-25



User Reviews:

  • Huey commented:
    I started using this code in a data logger project and it was a great jump start. I did have a little trouble when logging at a high rate of speed and ended up adding 2 lines to the code below to correct the problem. PRI transfer(read,status,data): val | mask ' '/** ' * Transfer data to/from Vinculum USB Host in SPI mode, using seperate data in and data out pin ' * ' * @param read True for read, false for write. ' * @pram status False to access command register, true to access status register. ' * @param data If write, byte to write. If read, not used. ' * @return 9bit value, bit0 is 0 if byte written succesfully or new data read ' * If read, b8-b1 is byte read ' */ '' For read, send 110, then read 8 bits (MSB first), read statusbit (total 12 clockpulses) '' For write, send 100, then write 8 bits (MSB first), read statusbit (total 12 clockpulses) repeat 'line added by Huey --------------------------------------------------------------- val := 0 data := $800 | ($400 & read) | ($200 & status) | (data << 1) mask := $800 outa[SPI_CLK]~~ ' At least one clock after deselecting outa[SPI_CLK]~ outa[SPI_CS]~~ ' Select chip repeat 12 ' Start, direction, address, 8 data, status outa[SPI_SDO] := (data & mask) > 0 val |= (mask & (ina[SPI_SDI] > 0)) outa[SPI_CLK]~~ ' Data valid on positive edge of clock outa[SPI_CLK]~ mask >>= 1 outa[SPI_CS]~ ' Deselect chip outa[SPI_CLK]~~ ' At least one clock after deselecting outa[SPI_CLK]~ while (((val & $001) > 0) AND NOT ($400 & read)) 'line added by Huey ----------------------------------------------- return val I also added the following code to get things started during initialization. This is only called in my program 1 time after power up. PUB flush 'very important to have this section in the code for logger to work on power up waitcnt(clkfreq/1000 + cnt) repeat if readByte <> -1 'if new data read waitcnt(clkfreq/1000 + cnt) else quit Overall it worked great. Huey
    February 21, 2010 12:53 a.m.




  • Comments on this Object:


    Post a comment:




    Please contact obex.support@parallax.com with comments or questions.

    Copyright 2011 by Parallax, Inc.