ADuCM355 SPI receive data missing

Hi !

I am trying the SPI master mode of the ADUCM 355. Basically, for every data that is sent out, there will be another data replied back from the slave. However, all the data that I read out from the buffer using the commend SpiRx are wrong. 

I used the Saleae logic analyzer to check the transmit and reply package on the MOSI and MISO pins. They are all correct but don't know why the data is not in the buffer. Below is my code.

SpiTxFifoFlush(pADI_SPI0, BITM_SPI_CTL_TFLUSH);           // Flush Tx FIFO
													
SpiTxFifoFlush(pADI_SPI0,0);
SpiCount(pADI_SPI0,1, 1,0);            // Setup to transfer size bytes to slave
pADI_SPI0->CTL |= BITM_SPI_CTL_TIM;        // SPI interrupt on Tx
ucTransmitInProgress = 1;				 
SpiTx(pADI_SPI0,*TxBuffer++);//TxBuffer[ucSpiCWrCnt++]			
while(ucTransmitInProgress); // wait for the transmit to comple
printf("SPI TX %x: ", SpiRx(pADI_SPI0)); // data read from here does not match with the one from the Logic Analyzer

Please let me know what is the problem with my code.

Thank you

  • 0
    •  Analog Employees 
    on Sep 27, 2021 10:08 AM

    Hi,

    Are the steps below done before reading SPI received data?

    pADI_SPI0->CTL &= ~(BITM_SPI_CTL_TIM); // SPI interrupt on Rx
    SpiRxFifoFlush(pADI_SPI0,BITM_SPI_CTL_RFLUSH); // Flush Master Rx FIFO
    SpiRxFifoFlush(pADI_SPI0,0);

    Also is better to set a separate RX array to store the received data.

    SpiCount(pADI_SPI0,length, 1,0); // Setup to read 14 bytes from slave
    ucBytesToRD = length;
    rxDat[ucRxCount++] = SpiRx(pADI_SPI0); // read SPI0 FIFO;
    ucReceiveInProgress = 1;