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.
|
#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.
|
|
|
spia_t * | spi_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...
|
|
Fast spi driver
Uses PASM from xSPIAsm.spin, modified from SPI_Asm.spin propeller tool library object.
- Author
- Tom Montemarano
- Version
- 0.5
- Copyright
- copyright (c) Tom Montemarano 2014, All Rights MIT Licensed
Modifications:
- Uses 'command' with PASM to load ClockDelay and ClockState variables into cog.
- spi_start parameter 'clockdelay_ns' is in nanosecs and function calculates ClockDelay value.
- device->command is either 0 or packed with 2 or 3 numbers to be used by pasm.
- command = 0 – pasm in idle loop.
- In spi_start:
- the number 4 is shifted left 16 bits to indicate 'startup'.
- the ClockDelay value is shifted left 2 bits.
- the ClockState value is in bit 0. All 3 values are or'd.
- In spi_in the number 2 is shifted left 16 bits, this is or'd with the address of the Dpin.
- In spi_out, the number 1 is shifted left 16 bits, and or'd with the address of the Dpin.
int spi_in |
( |
spia_t * |
device, |
|
|
int |
DQ, |
|
|
int |
CLK, |
|
|
int |
MD, |
|
|
int |
BIT |
|
) |
| |
Receive data from SPI device.
- Parameters
-
*device | SPI Device ID returned by spi_start |
DQ | Data in pin |
CLK | Clock pin |
MD | SPI SHIFTIN Mode (0, 1, 2, 3) |
BIT | Number 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
-
*device | SPI Device ID returned by spi_start |
DQ | Data out pin |
CLK | Clock pin |
MD | SPI SHIFTOUT Mode (4 or 5) |
BIT | Number of bits to send |
VLU | Data 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
-
*device | SPI Device ID returned by spi_start |