Bill Greiman
Well-known member
Code:
SPI.beginTransaction just doesn't fit well. It mixes locks with device setup. Why is there not a simple SPI.beginTransaction() that doesn't muck with SPI settings?
For SdFat I plan to use two weak functions for sharing the SPI bus, sdSpiLock(), and sdSpiUnlock().
For ChibiOS you would replace the weak functions with something like this in your sketch:
Code:
Mutex spiMutex;
inline void sdSpiLock() {chMtxLock(&spiMutex);}
inline void sdSpiUnlock() {chMtxUnlock();}
What would be the best solution for sdSpiLock() with the new SPI transactions?
I assume sdSpiUnlock() could be:
Code:
inline void sdSpiUnlock() {SPI.endTransaction();}
Edit: setting SPI speed should not be restricted to beginTransaction. SD cards must be initialized at low speed then shifted to high speed.
Code:
// This function is deprecated. New applications should use
// beginTransaction() to configure SPI settings.
inline static void setClockDivider(uint8_t clockDiv) {
SPCR = (SPCR & ~SPI_CLOCK_MASK) | (clockDiv & SPI_CLOCK_MASK);
SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((clockDiv >> 2) & SPI_2XCLOCK_MASK);
}
Last edited: