aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-07-05 10:29:52 -0400
committerKevin O'Connor <kevin@koconnor.net>2018-07-05 10:29:52 -0400
commit1eb416002bf9abfc2fe9d30e9c42c44704e0f791 (patch)
tree199d724add10cb8994113956fdfec148d8ddda86
parent7e9ee6aef70ceb6a561810c097262fd0c2d80f58 (diff)
downloadkutter-1eb416002bf9abfc2fe9d30e9c42c44704e0f791.tar.gz
kutter-1eb416002bf9abfc2fe9d30e9c42c44704e0f791.tar.xz
kutter-1eb416002bf9abfc2fe9d30e9c42c44704e0f791.zip
sam3x8e: Read from the SPI_RDR on SPI send even if no data needed
Be sure to read the SPI_RDR as that clears the RDRF flag. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--src/sam3x8e/spi.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/sam3x8e/spi.c b/src/sam3x8e/spi.c
index 791d71b3..3bbf6548 100644
--- a/src/sam3x8e/spi.c
+++ b/src/sam3x8e/spi.c
@@ -4,13 +4,10 @@
//
// This file may be distributed under the terms of the GNU GPLv3 license.
-#include <stddef.h> // NULL
-#include "autoconf.h"
+#include <sam3x8e.h> // REGPTR
#include "command.h" // shutdown
-#include "gpio.h"
-#include "sched.h"
-#include <sam3x8e.h>
-#include <string.h>
+#include "gpio.h" // gpio_peripheral
+#include "sched.h" // sched_shutdown
#define REGPTR SPI0
#define PERIPH_ID ID_SPI0
@@ -109,7 +106,8 @@ spi_transfer(struct spi_config config, uint8_t receive_data
while (len--) {
pSpi->SPI_TDR = *data;
// wait for receive register
- while (!(pSpi->SPI_SR & SPI_SR_RDRF)) { asm volatile("nop"); };
+ while (!(pSpi->SPI_SR & SPI_SR_RDRF))
+ ;
// get data
*data++ = pSpi->SPI_RDR;
}
@@ -117,7 +115,10 @@ spi_transfer(struct spi_config config, uint8_t receive_data
while (len--) {
pSpi->SPI_TDR = *data++;
// wait for receive register
- while (!(pSpi->SPI_SR & SPI_SR_RDRF)) { asm volatile("nop"); };
+ while (!(pSpi->SPI_SR & SPI_SR_RDRF))
+ ;
+ // read data (to clear RDRF)
+ pSpi->SPI_RDR;
}
}
}