Skip to content

Commit 20ca436

Browse files
PaulStoffregencmaglie
authored andcommittedDec 2, 2014
Fix SPI transaction mismatch errors
1 parent 37115d0 commit 20ca436

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed
 

‎libraries/SD/utility/Sd2Card.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,24 @@ uint32_t Sd2Card::cardSize(void) {
157157
}
158158
}
159159
//------------------------------------------------------------------------------
160+
static uint8_t chip_select_asserted = 0;
161+
160162
void Sd2Card::chipSelectHigh(void) {
161163
digitalWrite(chipSelectPin_, HIGH);
162164
#ifdef USE_SPI_LIB
163-
SPI.endTransaction();
165+
if (chip_select_asserted) {
166+
chip_select_asserted = 0;
167+
SPI.endTransaction();
168+
}
164169
#endif
165170
}
166171
//------------------------------------------------------------------------------
167172
void Sd2Card::chipSelectLow(void) {
168173
#ifdef USE_SPI_LIB
169-
SPI.beginTransaction(settings);
174+
if (!chip_select_asserted) {
175+
chip_select_asserted = 1;
176+
SPI.beginTransaction(settings);
177+
}
170178
#endif
171179
digitalWrite(chipSelectPin_, LOW);
172180
}

0 commit comments

Comments
 (0)
Please sign in to comment.