1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 14:33:52 +01:00

cpu/cc2538: fix spi_transfer_bytes()

Always wait for RNE before reading DR.
Fixes always reading in the !out_buf case.
This commit is contained in:
Benjamin Valentin 2019-09-30 13:11:11 +02:00
parent 6cbb7ad1a0
commit bf1eca338f

View File

@ -145,14 +145,13 @@ void spi_transfer_bytes(spi_t bus, spi_cs_t cs, bool cont,
dev(bus)->DR;
}
}
else if (!out_buf) { /*TODO this case is currently untested */
else if (!out_buf) {
size_t in_cnt = 0;
for (size_t i = 0; i < len; i++) {
while (!(dev(bus)->SR & SSI_SR_TNF)) {}
dev(bus)->DR = 0;
if (dev(bus)->SR & SSI_SR_RNE) {
in_buf[in_cnt++] = dev(bus)->DR;
}
while (!(dev(bus)->SR & SSI_SR_RNE)) {}
in_buf[in_cnt++] = dev(bus)->DR;
}
/* get remaining bytes */
while (dev(bus)->SR & SSI_SR_RNE) {
@ -163,7 +162,7 @@ void spi_transfer_bytes(spi_t bus, spi_cs_t cs, bool cont,
for (size_t i = 0; i < len; i++) {
while (!(dev(bus)->SR & SSI_SR_TNF)) {}
dev(bus)->DR = out_buf[i];
while (!(dev(bus)->SR & SSI_SR_RNE)){}
while (!(dev(bus)->SR & SSI_SR_RNE)) {}
in_buf[i] = dev(bus)->DR;
}
/* wait until no more busy */