aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
authorPerry Hung <iperry@gmail.com>2010-09-14 23:09:38 -0400
committerPerry Hung <iperry@gmail.com>2010-09-14 23:09:38 -0400
commit9180233b971aecb621ae54307c72ef074773640f (patch)
tree831075dfa891974e7edf49ebaa374d5f709abd0e /libmaple
parent1cec807e44da29c5a122e57120174f4711d95f25 (diff)
downloadlibrambutan-9180233b971aecb621ae54307c72ef074773640f.tar.gz
librambutan-9180233b971aecb621ae54307c72ef074773640f.zip
Check different set of flags for SPI master transmit
Tested on wishield, would like some more testing if anybody has more things that speak spi
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/spi.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/libmaple/spi.c b/libmaple/spi.c
index 68855a5..4b02f44 100644
--- a/libmaple/spi.c
+++ b/libmaple/spi.c
@@ -115,14 +115,14 @@ void spi_init(uint32 spi_num,
uint8 spi_tx_byte(uint32 spi_num, uint8 data) {
SPI *spi;
- ASSERT(spi_num == 1 || spi_num == 2);
-
spi = (spi_num == 1) ? (SPI*)SPI1_BASE : (SPI*)SPI2_BASE;
+ while (!(spi->SR & SR_TXE))
+ ;
+
spi->DR = data;
- while (!(spi->SR & SR_TXE) ||
- (spi->SR & SR_BSY))
+ while (!(spi->SR & SR_RXNE))
;
return spi->DR;
@@ -141,11 +141,14 @@ uint8 spi_tx(uint32 spi_num, uint8 *buf, uint32 len) {
}
while (i < len) {
+ while (!(spi->SR & SR_TXE))
+ ;
+
spi->DR = buf[i];
- while (!(spi->SR & SR_TXE) ||
- (spi->SR & SR_BSY) ||
- !(spi->SR & SR_RXNE))
+
+ while (!(spi->SR & SR_RXNE))
;
+
rc = spi->DR;
i++;
}