aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
authorPerry Hung <iperry@alum.mit.edu>2010-04-28 19:19:34 -0400
committerPerry Hung <iperry@alum.mit.edu>2010-04-28 19:19:34 -0400
commita7031b147c9ee77d1ed04ec419a7a23edd08014a (patch)
treecebd5e51dfba2c0af4d47156e909fb190af77069 /libmaple
parent28feb18a8f6d3dd2d0d78a40d4213407fb54e5dd (diff)
downloadlibrambutan-a7031b147c9ee77d1ed04ec419a7a23edd08014a.tar.gz
librambutan-a7031b147c9ee77d1ed04ec419a7a23edd08014a.zip
Various SPI changes.
-Read DR after each master send, return the response. -Added a send function to allow you to pass buffers to the SPI peripheral instead of goin a byte at a time.
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/spi.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/libmaple/spi.c b/libmaple/spi.c
index 4f34d1a..aa75c5f 100644
--- a/libmaple/spi.c
+++ b/libmaple/spi.c
@@ -130,7 +130,8 @@ uint8 spi_tx_byte(uint32 spi_num, uint8 data) {
uint8 spi_tx(uint32 spi_num, uint8 *buf, uint32 len) {
SPI *spi;
- uint32 i;
+ uint32 i = 0;
+ uint8 rc;
ASSERT(spi_num == 1 || spi_num == 2);
spi = (spi_num == 1) ? (SPI*)SPI1_BASE : (SPI*)SPI2_BASE;
@@ -140,13 +141,15 @@ uint8 spi_tx(uint32 spi_num, uint8 *buf, uint32 len) {
}
while (i < len) {
- spi->DR = buf[len];
+ spi->DR = buf[i];
while (!(spi->SR & SR_TXE) ||
- (spi->SR & SR_BSY))
+ (spi->SR & SR_BSY) ||
+ !(spi->SR & SR_RXNE))
;
+ rc = spi->DR;
i++;
}
- return spi->DR;
+ return rc;
}
static void spi_gpio_cfg(const spi_dev *dev) {