From b44d7bed91116ccddc1d018781eede3d187aad42 Mon Sep 17 00:00:00 2001 From: Fabio Utzig Date: Mon, 17 Oct 2016 12:01:37 +0000 Subject: Fixed collision in multi-byte SPI write git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9865 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/AVR/hal_spi_lld.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'os') diff --git a/os/hal/ports/AVR/hal_spi_lld.c b/os/hal/ports/AVR/hal_spi_lld.c index 6a89ce112..638f778b1 100644 --- a/os/hal/ports/AVR/hal_spi_lld.c +++ b/os/hal/ports/AVR/hal_spi_lld.c @@ -69,24 +69,25 @@ OSAL_IRQ_HANDLER(SPI_STC_vect) { spip->rxbuf[spip->rxidx++] = SPDR; // receive } - /* spi_lld_exchange, spi_lld_send or spi_lld_ignore */ - if (spip->txidx < spip->txbytes) { - if (spip->txbuf) { - SPDR = spip->txbuf[spip->txidx++]; // send - } else { - SPDR = 0; spip->txidx++; // dummy send - } - } - - /* spi_lld_send */ - else if (spip->rxidx < spip->rxbytes) { /* rx not done */ - SPDR = 0; // dummy send to keep the clock going - } - /* rx done and tx done */ if (spip->rxidx >= spip->rxbytes && spip->txidx >= spip->txbytes) { _spi_isr_code(spip); } + else { + /* spi_lld_exchange, spi_lld_send or spi_lld_ignore */ + if (spip->txidx < spip->txbytes) { + if (spip->txbuf) { + SPDR = spip->txbuf[spip->txidx++]; // send + } else { + SPDR = 0; spip->txidx++; // dummy send + } + } + + /* spi_lld_receive */ + else if (spip->rxidx < spip->rxbytes) { /* rx not done */ + SPDR = 0; // dummy send to keep the clock going + } + } OSAL_IRQ_EPILOGUE(); } -- cgit v1.2.3