Hi,
I'm attempting to communicate with an external adc (LTC1864L) , but the results that I'm reading back are wrong. My spi setup is as follows:
/* Configure the spi module
* SCK synchronizes the data transfer with each bit
* being transmitted from SDO on the falling SCK edge.
* The receiving system should capture the data from
* SDO on the rising edge of SCK
*/
sensor->cfg.whichCtar = kDSPI_Ctar0;
sensor->cfg.ctarConfig.baudRate = SPI_BAUDRATE;
sensor->cfg.ctarConfig.bitsPerFrame = 16U;
sensor->cfg.ctarConfig.cpol = kDSPI_ClockPolarityActiveLow;
sensor->cfg.ctarConfig.cpha = kDSPI_ClockPhaseFirstEdge;
sensor->cfg.ctarConfig.direction = kDSPI_MsbFirst;
sensor->cfg.ctarConfig.pcsToSckDelayInNanoSec = 1000000000U / SPI_BAUDRATE;
sensor->cfg.ctarConfig.lastSckToPcsDelayInNanoSec = 1000000000U / SPI_BAUDRATE;
sensor->cfg.ctarConfig.betweenTransferDelayInNanoSec = 1000000000U / SPI_BAUDRATE;
sensor->cfg.whichPcs = kDSPI_Pcs0;
sensor->cfg.pcsActiveHighOrLow = kDSPI_PcsActiveLow;
sensor->cfg.enableContinuousSCK = false;
sensor->cfg.enableRxFifoOverWrite = true;
sensor->cfg.enableModifiedTimingFormat = false;
sensor->cfg.samplePoint = kDSPI_SckToSin2Clock;
DSPI_MasterInit(SPI1, &sensor->cfg, CLOCK_GetFreq(DSPI1_CLK_SRC));
Baudrate is set to 500k. The transfer is initialized as follows (SPI_TXSIZE = 2):
/* Clear buffer */
sensor->rxData[0] = 0;
sensor->rxData[1] = 0;
/* Start master transfer */
sensor->xfer.txData = sensor->txData;
sensor->xfer.rxData = sensor->rxData;
sensor->xfer.dataSize = SPI_TXSIZE;
sensor->xfer.configFlags = kDSPI_MasterCtar0 | kDSPI_MasterPcs0 | kDSPI_MasterPcsContinuous;
DSPI_MasterTransferCreateHandle (SPI1, &g_m_handle, SENSOR_MasterCb, NULL);
DSPI_MasterTransferNonBlocking (SPI1, &g_m_handle, &sensor->xfer);
The scope shows the following image:
While the rxData contains 0x12, 0x00 which is clearly wrong. Is there something that I'm missing?
Hi ,
I checked the LTC1864L datasheet, the SPI output data with MSB first:
So, the data you get is 0x0018.
Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------