Skip to content
This repository was archived by the owner on Apr 16, 2021. It is now read-only.

Commit 92833a2

Browse files
committed
SPI: fix transfer16
Borrow implementation for samd core Should fix #85
1 parent d63c5b0 commit 92833a2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

libraries/SPI/SPI.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,18 @@ uint8_t arduino::MbedSPI::transfer(uint8_t data) {
3232
}
3333

3434
uint16_t arduino::MbedSPI::transfer16(uint16_t data) {
35-
uint8_t ret[2];
36-
dev->write((const char*)&data, 2, (char*)ret, 2);
37-
return ret[0] << 8 | ret[1];
35+
36+
union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } t;
37+
t.val = data;
38+
39+
if (settings.getBitOrder() == LSBFIRST) {
40+
t.lsb = transfer(t.lsb);
41+
t.msb = transfer(t.msb);
42+
} else {
43+
t.msb = transfer(t.msb);
44+
t.lsb = transfer(t.lsb);
45+
}
46+
return t.val;
3847
}
3948

4049
void arduino::MbedSPI::transfer(void *buf, size_t count) {

0 commit comments

Comments
 (0)