Skip to content

Commit 5678bb9

Browse files
Don't break transfer16 into 2 8-bit CS periods (#1764)
With HW chip select enabled, transfer16's 2 individual byte transfers will actualy deassert CS for a brief instant between bytes. Avoid this by doing a single multi-byte (2) tranfer of 16b.
1 parent 5ecef16 commit 5678bb9

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

libraries/SPI/src/SPI.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,11 @@ uint16_t SPIClassRP2040::transfer16(uint16_t data) {
124124
}
125125
data = (_spis.getBitOrder() == MSBFIRST) ? data : reverse16Bit(data);
126126
DEBUGSPI("SPI::transfer16(%04x), cpol=%d, cpha=%d\n", data, cpol(), cpha());
127-
uint8_t msb, lsb;
128-
msb = (data >> 8) & 0xff;
129-
lsb = data & 0xff;
130-
spi_write_read_blocking(_spi, &msb, &msb, 1);
131-
spi_write_read_blocking(_spi, &lsb, &lsb, 1);
132-
ret = ((msb << 8) | (lsb & 0xff)) & 0xffff;
127+
uint8_t d[2];
128+
d[0] = (data >> 8) & 0xff;
129+
d[1] = data & 0xff;
130+
spi_write_read_blocking(_spi, d, d, 2);
131+
ret = ((d[0] << 8) | (d[1] & 0xff)) & 0xffff;
133132
ret = (_spis.getBitOrder() == MSBFIRST) ? ret : reverse16Bit(ret);
134133
DEBUGSPI("SPI: read back %02x\n", ret);
135134
return ret;

0 commit comments

Comments
 (0)