Skip to content

Commit b7e750e

Browse files
sandeepmistrymattairtech
authored andcommitted
Add SPI. transfer16(...) API
1 parent f1f0297 commit b7e750e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

libraries/SPI/SPI.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,22 @@ byte SPIClass::transfer(uint8_t data)
194194
return _p_sercom->readDataSPI() & 0xFF;
195195
}
196196

197+
uint16_t SPIClass::transfer16(uint16_t data) {
198+
union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } t;
199+
200+
t.val = data;
201+
202+
if (_p_sercom->getDataOrderSPI() == LSB_FIRST) {
203+
t.lsb = transfer(t.lsb);
204+
t.msb = transfer(t.msb);
205+
} else {
206+
t.msb = transfer(t.msb);
207+
t.lsb = transfer(t.lsb);
208+
}
209+
210+
return t.val;
211+
}
212+
197213
void SPIClass::attachInterrupt() {
198214
// Should be enableInterrupt()
199215
}

libraries/SPI/SPI.h

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class SPIClass {
9696

9797

9898
byte transfer(uint8_t data);
99+
uint16_t transfer16(uint16_t data);
99100
inline void transfer(void *buf, size_t count);
100101

101102
// Transaction Functions

0 commit comments

Comments
 (0)