Bill Greiman
Well-known member
I have posted two beta libraries on GitHub to help with problems sharing SPI between SdFat and interrupt routines that access the SPI bus.
The first, DigitalIO https://github.com/greiman/DigitalIO-beta, has general software SPI support for Teensy 3.x. The SoftSPI class can be used to access SPI devices at 4-5 MHz using any digital pins. See the testSoftSPI example.
The second, SdFat https://github.com/greiman/SdFat-beta, has support for SPI transactions and software SPI access to SD cards.
To use SPI transactions in SdFat, edit this section of SdFatConfig.h.
To use software SPI in SdFat, edit this section of SdFatConfig.h
The first, DigitalIO https://github.com/greiman/DigitalIO-beta, has general software SPI support for Teensy 3.x. The SoftSPI class can be used to access SPI devices at 4-5 MHz using any digital pins. See the testSoftSPI example.
The second, SdFat https://github.com/greiman/SdFat-beta, has support for SPI transactions and software SPI access to SD cards.
To use SPI transactions in SdFat, edit this section of SdFatConfig.h.
Code:
//------------------------------------------------------------------------------
/**
* Set ENABLE_SPI_TRANSACTION nonzero to enable the SPI transaction feature
* of the standard Arduino SPI library. You must include SPI.h in your
* sketches when ENABLE_SPI_TRANSACTION is nonzero.
*/
#define ENABLE_SPI_TRANSACTION 0
//------------------------------------------------------------------------------
/**
* Set ENABLE_SPI_YIELD nonzero to enable release of the SPI bus during
* SD card busy waits.
*
* This will allow interrupt routines to access the SPI bus if
* ENABLE_SPI_TRANSACTION is nonzero.
*
* Setting ENABLE_SPI_YIELD will introduce some extra overhead and will
* slightly slow transfer rates. A few older SD cards may fail when
* ENABLE_SPI_YIELD is nonzero.
*/
#define ENABLE_SPI_YIELD 0
To use software SPI in SdFat, edit this section of SdFatConfig.h
Code:
//------------------------------------------------------------------------------
/**
* Define AVR_SOF_SPI nonzero to use software SPI on all AVR Arduinos.
*/
#define AVR_SOFT_SPI 0
//------------------------------------------------------------------------------
/**
* Define DUE_SOFT_SPI nonzero to use software SPI on Due Arduinos.
*/
#define DUE_SOFT_SPI 0
//------------------------------------------------------------------------------
/**
* Define LEONARDO_SOFT_SPI nonzero to use software SPI on Leonardo Arduinos.
* LEONARDO_SOFT_SPI allows an unmodified 328 Shield to be used
* on Leonardo Arduinos.
*/
#define LEONARDO_SOFT_SPI 0
//------------------------------------------------------------------------------
/**
* Define MEGA_SOFT_SPI nonzero to use software SPI on Mega Arduinos.
* MEGA_SOFT_SPI allows an unmodified 328 Shield to be used
* on Mega Arduinos.
*/
#define MEGA_SOFT_SPI 0
//------------------------------------------------------------------------------
/**
* Set TEENSY3_SOFT_SPI nonzero to use software SPI on Teensy 3.x boards.
*/
#define TEENSY3_SOFT_SPI 0
//------------------------------------------------------------------------------
/**
* Define software SPI pins. Default allows Uno shields to be used on other
* boards.
*/
// define software SPI pins
/** Default Software SPI chip select pin */
uint8_t const SOFT_SPI_CS_PIN = 10;
/** Software SPI Master Out Slave In pin */
uint8_t const SOFT_SPI_MOSI_PIN = 11;
/** Software SPI Master In Slave Out pin */
uint8_t const SOFT_SPI_MISO_PIN = 12;
/** Software SPI Clock pin */
uint8_t const SOFT_SPI_SCK_PIN = 13;