libspiasm  0.5
SPI Driver
 All Data Structures Files Functions Variables Typedefs Macros
Data Structures | Macros | Typedefs | Functions
spiasm.h File Reference

Fast spi driver
Uses PASM from xSPIAsm.spin, modified from SPI_Asm.spin propeller tool library object. More...

#include "simpletools.h"

Go to the source code of this file.

Data Structures

struct  spi_struct
 

Macros

#define _Title_   0
 **************** SPI Modes ****************
 
#define MPRE   0
 Rx Most Significant Bit first - data valid before clock.
 
#define LPRE   1
 Rx Least Significant Bit first - data valid before clock.
 
#define MPOST   2
 Rx Most Significant Bit first - data valid after clock.
 
#define LPOST   3
 Rx Least Significant Bit first - data valid after clock.
 
#define LFIRST   4
 Tx Least Significant Bit first ; data valid after clock.
 
#define MFIRST   5
 Tx Most Significant Bit first ; data valid after clock.
 

Typedefs

typedef struct spi_struct spia_t
 Data type for struct.
 

Functions

spia_tspi_start (int clockdelay_ns, int clockstate)
 Starts the spi cog, loads ClockState and ClockDelay PASM variables. More...
 
void spi_stop (spia_t *device)
 Stop and Release Cog. More...
 
void spi_out (spia_t *device, int DQ, int CLK, int MD, int BIT, int VLU)
 Send data to SPI device. More...
 
int spi_in (spia_t *device, int DQ, int CLK, int MD, int BIT)
 Receive data from SPI device. More...
 

Detailed Description

Fast spi driver
Uses PASM from xSPIAsm.spin, modified from SPI_Asm.spin propeller tool library object.

Author
Tom Montemarano
Version
0.5

Modifications:

Function Documentation

int spi_in ( spia_t device,
int  DQ,
int  CLK,
int  MD,
int  BIT 
)

Receive data from SPI device.

Parameters
*deviceSPI Device ID returned by spi_start
DQData in pin
CLKClock pin
MDSPI SHIFTIN Mode (0, 1, 2, 3)
BITNumber of bits to receive
Returns
Value sent by SPI device
void spi_out ( spia_t device,
int  DQ,
int  CLK,
int  MD,
int  BIT,
int  VLU 
)

Send data to SPI device.

Parameters
*deviceSPI Device ID returned by spi_start
DQData out pin
CLKClock pin
MDSPI SHIFTOUT Mode (4 or 5)
BITNumber of bits to send
VLUData Value to send
spia_t* spi_start ( int  clockdelay_ns,
int  clockstate 
)

Starts the spi cog, loads ClockState and ClockDelay PASM variables.

Parameters
clockstate- 0 = start clock low, 1 = start clock high
clockdelay_ns- Actual delay in nanoseconds (1000ns = 1 usec), not less than 300ns.
  • This is different than the spin object that uses ClockDelay.
  • spi_start calculates the ClockDelay value from clockdelay_ns.
  • ClockDelay = ((clockdelay_ns) - 250ns)) / 50ns.
    • e.g. for 2 usec (i.e. 2000 ns): ClockDelay will equal 35.
    • for 1 usec ClockDelay will equal 15.
Returns
spia_t pointer for use as an identifier for spi functions
void spi_stop ( spia_t device)

Stop and Release Cog.

Parameters
*deviceSPI Device ID returned by spi_start