Skip to content

Commit fb90221

Browse files
committed
fix mode 3
1 parent aa29b35 commit fb90221

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

Adafruit_SPIDevice.cpp

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,51 +195,74 @@ void Adafruit_SPIDevice::transfer(uint8_t *buffer, size_t len) {
195195
if (bitdelay_us) {
196196
delayMicroseconds(bitdelay_us);
197197
}
198-
198+
199199
if (_dataMode == SPI_MODE0 || _dataMode == SPI_MODE2) {
200200
towrite = send & b;
201201
if ((_mosi != -1) && (lastmosi != towrite)) {
202202
BUSIO_WRITE_MOSI(towrite);
203203
lastmosi = towrite;
204204
}
205-
205+
206206
BUSIO_SET_CLOCK_HIGH();
207-
207+
208208
if (bitdelay_us) {
209209
delayMicroseconds(bitdelay_us);
210210
}
211-
211+
212212
if (_miso != -1) {
213213
if (BUSIO_READ_MISO())
214214
reply |= b;
215-
}
216215
}
217-
216+
218217
BUSIO_SET_CLOCK_LOW();
219-
220-
} else { // if (_dataMode == SPI_MODE1 || _dataMode == SPI_MODE3)
221-
218+
219+
} else if (_dataMode == SPI_MODE3) {
220+
221+
if (_mosi != -1) { // transmit on falling edge
222+
BUSIO_WRITE_MOSI(send & b);
223+
}
224+
225+
BUSIO_SET_CLOCK_LOW();
226+
227+
if (bitdelay_us) {
228+
delayMicroseconds(bitdelay_us);
229+
}
230+
222231
BUSIO_SET_CLOCK_HIGH();
223-
232+
224233
if (bitdelay_us) {
225234
delayMicroseconds(bitdelay_us);
226235
}
227-
236+
237+
if (_miso != -1) { // read on rising edge
238+
if (BUSIO_READ_MISO()) {
239+
reply |= b;
240+
}
241+
}
242+
243+
} else { // || _dataMode == SPI_MODE1)
244+
245+
BUSIO_SET_CLOCK_HIGH();
246+
247+
if (bitdelay_us) {
248+
delayMicroseconds(bitdelay_us);
249+
}
250+
228251
if (_mosi != -1) {
229252
BUSIO_WRITE_MOSI(send & b);
230253
}
231-
254+
232255
BUSIO_SET_CLOCK_LOW();
233-
256+
234257
if (_miso != -1) {
235258
if (BUSIO_READ_MISO()) {
236259
reply |= b;
237260
}
238261
}
239262
}
240-
if (_miso != -1) {
241-
buffer[i] = reply;
242-
}
263+
}
264+
if (_miso != -1) {
265+
buffer[i] = reply;
243266
}
244267
}
245268
return;

0 commit comments

Comments
 (0)