AnsweredAssumed Answered

Kinetis MKV11Z128VFM7 dspi edma slave, jumbled data, sdk 2.2.0

Question asked by Erik Lidgren on Jun 15, 2017
Latest reply on Jun 30, 2017 by Erik Lidgren

Hi

 

I've a MKV11Z128VFM7 that I want to use as a spi slave. I'm trying to get edma and dspi to work, but the data is jumbled.

E.g I received:

1A, 1C, 1D, 1E, 1F, 20, 21, 1E, 22, 1F, 23, 20, 24, 21, 25, 22, 15

When the master sent:

15, 16, 17, 18, 19, 1A, 1B, 1C, 1D, 1E, 1F, 20, 21, 22, 23, 24, 25

Same in the other direction, data comes out different from what's in the transmit buffer.

 

Spi without dma is working, using the function DSPI_SlaveTransferNonBlocking. Data is sent and received correctly.

 

Here is my init code. Have I missed something or am I using it wrong?

dspi_slave_edma_handle_t spiHandle;
edma_handle_t g_spiTxDmaHandle;
edma_handle_t g_spiRxDmaHandle;
dspi_transfer_t xfer;
edma_config_t edmaConfig;

#define SPI_TX_DMA_CHANNEL 3
#define SPI_RX_DMA_CHANNEL 0

#define SPI_TX_DMA_REQUEST (kDmaRequestMux0SPI0Tx)
#define SPI_RX_DMA_REQUEST (kDmaRequestMux0SPI0Rx)

 

uint8_t testdata[17] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};

 

void init(void)
{

// Sets up the DMA.
DMAMUX_Init(DMAMUX0);
DMAMUX_SetSource(DMAMUX0, SPI_TX_DMA_CHANNEL, SPI_TX_DMA_REQUEST);
DMAMUX_EnableChannel(DMAMUX0, SPI_TX_DMA_CHANNEL);
DMAMUX_SetSource(DMAMUX0, SPI_RX_DMA_CHANNEL, SPI_RX_DMA_REQUEST);
DMAMUX_EnableChannel(DMAMUX0, SPI_RX_DMA_CHANNEL);

/* EDMA init */
/*
* userConfig.enableRoundRobinArbitration = false;
* userConfig.enableHaltOnError = true;
* userConfig.enableContinuousLinkMode = false;
* userConfig.enableDebugMode = false;
*/
EDMA_GetDefaultConfig(&edmaConfig);
EDMA_Init(DMA0, &edmaConfig);

/* Slave config */
slaveConfig.whichCtar = kDSPI_Ctar0;
slaveConfig.ctarConfig.bitsPerFrame = 8;
slaveConfig.ctarConfig.cpol = kDSPI_ClockPolarityActiveHigh;
slaveConfig.ctarConfig.cpha = kDSPI_ClockPhaseFirstEdge;
slaveConfig.enableContinuousSCK = false;
slaveConfig.enableRxFifoOverWrite = false;
slaveConfig.enableModifiedTimingFormat = false;
slaveConfig.samplePoint = kDSPI_SckToSin0Clock;
DSPI_SlaveInit(DSPI_INSTANCE, &slaveConfig);


/* Creates the DMA handle. */
memset(&(g_spiTxDmaHandle), 0, sizeof(g_spiTxDmaHandle));
memset(&(g_spiRxDmaHandle), 0, sizeof(g_spiRxDmaHandle));
EDMA_CreateHandle(&g_spiTxDmaHandle, DMA0, SPI_TX_DMA_CHANNEL);
EDMA_CreateHandle(&g_spiRxDmaHandle, DMA0, SPI_RX_DMA_CHANNEL);
DSPI_SlaveTransferCreateHandleEDMA(SPI0, &spiHandle, DSPI_EDMASlaveUserCallback, NULL, &g_spiTxDmaHandle, &g_spiRxDmaHandle);

 

// Prepares to send.
xfer.txData = testdata;//(uint8_t*)&txSpiPacket;
xfer.rxData = (uint8_t*)&rxSpiPacket;
xfer.dataSize = SPI_BUFFER_SIZE;
xfer.configFlags = kDSPI_SlaveCtar0;
// Sends out.
DSPI_SlaveTransferEDMA(SPI0, &spiHandle, &xfer);

 

}

 

Best regards

Erik

Outcomes