Permalink
Browse files

fix SD library bit bang SPI from clobbering concurrent processor SPI …

…usage
  • Loading branch information...
1 parent 4a49be4 commit e4c7faf759eddc2ba7fd20fdb761ccc882bd5357 @KeithV KeithV committed Dec 12, 2012
Showing with 15 additions and 3 deletions.
  1. +15 −3 hardware/pic32/libraries/SD/utility/Sd2Card.cpp
@@ -43,6 +43,8 @@
#define bnSPI2TXIE 6
uint32_t spi_state;
+uint8_t fspi_state_saved = false;
+uint32_t interrupt_state = 0;
/** Soft SPI receive */
uint8_t spiRec(void) {
@@ -158,14 +160,24 @@ uint32_t Sd2Card::cardSize(void) {
void Sd2Card::chipSelectHigh(void) {
digitalWrite(chipSelectPin_, HIGH);
#if defined(_BOARD_MEGA_) || defined(_BOARD_UNO_) || defined(_BOARD_UC32_)
- SPI2CON = spi_state;
+ if(fspi_state_saved)
+ {
+ SPI2CON = spi_state;
+ fspi_state_saved = false;
+ INTRestoreInterrupts(interrupt_state);
+ }
#endif
}
//------------------------------------------------------------------------------
void Sd2Card::chipSelectLow(void) {
#if defined(_BOARD_MEGA_) || defined(_BOARD_UNO_) || defined(_BOARD_UC32_)
- spi_state = SPI2CON;
- SPI2CONbits.ON = 0;
+ if(!fspi_state_saved)
+ {
+ interrupt_state = INTDisableInterrupts();
+ spi_state = SPI2CON;
+ SPI2CONbits.ON = 0;
+ fspi_state_saved = true;
+ }
#endif
digitalWrite(chipSelectPin_, LOW);
}

0 comments on commit e4c7faf

Please sign in to comment.