From 61a026dedda1082c27ebb91ab1392c373fc69ff9 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sat, 16 Jun 2018 13:45:01 -0600 Subject: [PATCH] /arch/arm/src/xmc4: Fix XMC4 SPI. It was working only for the first transfer --- arch/arm/src/xmc4/xmc4_spi.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/arm/src/xmc4/xmc4_spi.c b/arch/arm/src/xmc4/xmc4_spi.c index 09f159a8e4..1c9a0ab791 100644 --- a/arch/arm/src/xmc4/xmc4_spi.c +++ b/arch/arm/src/xmc4/xmc4_spi.c @@ -1431,20 +1431,19 @@ static void spi_exchange(struct spi_dev_s *dev, const void *txbuffer, data = 0xffff; } - /* Set the PCS field in the value written to the TDR */ - - /*data |= pcs; */ - - /* Wait for any previous data written to the TDR to be transferred - * to the serializer. - */ - - /*while ((spi_getreg(spi, XMC4_SPI_SR_OFFSET) & SPI_INT_TDRE) == 0); */ - /* Write the data to transmitted to the Transmit Data Register (TDR) */ spi_putreg(spi, data, XMC4_USIC_TBUF_OFFSET); + /* Wait until the last bit be transfered */ + + while ((spi_getreg(spi, XMC4_USIC_PSR_OFFSET) & + (USIC_PSR_TSIF)) == 0) + { + } + + spi_putreg(spi, USIC_PSCR_CTSIF, XMC4_USIC_PSCR_OFFSET); + /* Wait to get some data */ while ((spi_getreg(spi, XMC4_USIC_PSR_OFFSET) & @@ -1452,6 +1451,8 @@ static void spi_exchange(struct spi_dev_s *dev, const void *txbuffer, { } + spi_putreg(spi, (USIC_PSCR_CRIF | USIC_PSCR_CAIF), XMC4_USIC_PSCR_OFFSET); + /* Read the received data from the SPI Data Register. */ data = spi_getreg(spi, XMC4_USIC_RBUF_OFFSET);