From 4e37e938e5c861d758168705e8d681d18d9a6243 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 20 Dec 2009 11:38:02 +0000 Subject: FatFS demo for LPC214x added. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1445 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/LPC214x/spi_lld.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'os/hal/platforms/LPC214x/spi_lld.c') diff --git a/os/hal/platforms/LPC214x/spi_lld.c b/os/hal/platforms/LPC214x/spi_lld.c index f3f3e13b7..6e7f7a44b 100644 --- a/os/hal/platforms/LPC214x/spi_lld.c +++ b/os/hal/platforms/LPC214x/spi_lld.c @@ -55,20 +55,23 @@ SPIDriver SPID1; * @param[out] rxbuf the pointer to the receive buffer or @p NULL */ void rw8(size_t n, const uint8_t *txbuf, uint8_t *rxbuf) { + size_t ntx = n; while (n > 0) { - if (SSPBase->SSP_SR & SR_RNE) { + uint32_t sr = SSPBase->SSP_SR; + if (sr & SR_RNE) { uint8_t w = SSPBase->SSP_DR; if (rxbuf != NULL) *rxbuf++ = w; n--; continue; /* Priority over transmission. */ } - if (SSPBase->SSP_SR & SR_TNF) { + if ((ntx > 0) && (sr & SR_TNF)) { if (txbuf != NULL) SSPBase->SSP_DR = *txbuf++; else - SSPBase->SSP_DR = 0xFF; + SSPBase->SSP_DR = 0xFFFFFFFF; + ntx--; } } } @@ -104,6 +107,9 @@ void spi_lld_start(SPIDriver *spip) { } /* Configuration.*/ SSPBase->SSP_CR1 = 0; + /* Emptying the receive FIFO, it happens to not be empty while debugging.*/ + while (SSPBase->SSP_SR & SR_RNE) + (void) SSPBase->SSP_DR; SSPBase->SSP_CR0 = spip->spd_config->spc_cr0; SSPBase->SSP_CPSR = spip->spd_config->spc_cpsr; SSPBase->SSP_CR1 = spip->spd_config->spc_cr1 | CR1_SSE; -- cgit v1.2.3