/* Master config */
masterConfig.whichCtar = kDSPI_Ctar0;
masterConfig.ctarConfig.baudRate = TRANSFER_BAUDRATE;
masterConfig.ctarConfig.bitsPerFrame = 16U;
masterConfig.ctarConfig.cpol = kDSPI_ClockPolarityActiveHigh;
masterConfig.ctarConfig.cpha = kDSPI_ClockPhaseFirstEdge;
masterConfig.ctarConfig.direction = kDSPI_MsbFirst; //kDSPI_LsbFirst // kDSPI_MsbFirst
masterConfig.ctarConfig.pcsToSckDelayInNanoSec = 1000000000U / TRANSFER_BAUDRATE;
masterConfig.ctarConfig.lastSckToPcsDelayInNanoSec = 1000000000U / TRANSFER_BAUDRATE;
masterConfig.ctarConfig.betweenTransferDelayInNanoSec = 1000000000U / TRANSFER_BAUDRATE;
masterConfig.whichPcs = EXAMPLE_DSPI_MASTER_PCS_FOR_INIT;
masterConfig.pcsActiveHighOrLow = kDSPI_PcsActiveLow;
masterConfig.enableContinuousSCK = false;
masterConfig.enableRxFifoOverWrite = false;
masterConfig.enableModifiedTimingFormat = false;
masterConfig.samplePoint = kDSPI_SckToSin0Clock;
srcClock_Hz = DSPI_MASTER_CLK_FREQ;
DSPI_MasterInit(EXAMPLE_DSPI_MASTER_BASEADDR, &masterConfig, srcClock_Hz);
/* Slave config */
slaveConfig.whichCtar = kDSPI_Ctar0;
slaveConfig.ctarConfig.bitsPerFrame = masterConfig.ctarConfig.bitsPerFrame;
slaveConfig.ctarConfig.cpol = masterConfig.ctarConfig.cpol;
slaveConfig.ctarConfig.cpha = masterConfig.ctarConfig.cpha;
slaveConfig.enableContinuousSCK = masterConfig.enableContinuousSCK;
slaveConfig.enableRxFifoOverWrite = masterConfig.enableRxFifoOverWrite;
slaveConfig.enableModifiedTimingFormat = masterConfig.enableModifiedTimingFormat;
slaveConfig.samplePoint = masterConfig.samplePoint;
DSPI_SlaveInit(EXAMPLE_DSPI_SLAVE_BASEADDR, &slaveConfig);
// DSPI_SlaveTransferCreateHandle(EXAMPLE_DSPI_SLAVE_BASEADDR, &g_s_handle, DSPI_SlaveUserCallback, NULL);
///* Set slave transfer to receive data */
// isTransferCompleted = false;
slaveXfer.txData = NULL;
slaveXfer.rxData = slaveRxData;
slaveXfer.dataSize = TRANSFER_SIZE;
slaveXfer.configFlags = kDSPI_SlaveCtar0;
GPIO_PortSet(GPIOC, 1U << BOARD_RESET_AD_PIN); //PTC3 RESET
//SysTick_DelayTicks(1U); // Delay 1000 ms
for (i = 0; i < 12000; i++)
{__NOP();}
GPIO_PortClear(GPIOC, 1U << BOARD_RESET_AD_PIN); //PTC3 RESET
GPIO_PortSet(GPIOE, 1U << 25U);
/* Start master transfer, receive data from slave */
masterXfer.txData = NULL;
masterXfer.rxData = masterRxData;
masterXfer.dataSize = TRANSFER_SIZE; //kDSPI_MasterPcsContinuous
masterXfer.configFlags = kDSPI_MasterCtar0 | EXAMPLE_DSPI_MASTER_PCS_FOR_TRANSFER | kDSPI_MasterActiveAfterTransfer; //kDSPI_MasterActiveAfterTransfer
slaveXfer.txData = NULL;
slaveXfer.rxData = slaveRxData;
slaveXfer.dataSize = TRANSFER_SIZE;
slaveXfer.configFlags = kDSPI_SlaveCtar0;
assert(NULL != &masterXfer);
uint16_t wordToSend = 0;
uint16_t wordReceived = 0;
uint8_t dummyData = DSPI_GetDummyDataInstance(EXAMPLE_DSPI_MASTER_BASEADDR);
uint8_t bitsPerFrame;
uint32_t command;
uint32_t lastCommand;
uint16_t *txData;
uint16_t *rxData;
uint32_t fifoSize;
uint32_t tmpMCR = 0;
dspi_command_data_config_t commandStruct;
/* If the transfer count is zero, then return immediately.*/
if (&masterXfer.dataSize == 0U)
{
return kStatus_InvalidArgument;
}
DSPI_StopTransfer(EXAMPLE_DSPI_MASTER_BASEADDR);
DSPI_DisableInterrupts(EXAMPLE_DSPI_MASTER_BASEADDR, (uint32_t)kDSPI_AllInterruptEnable);
DSPI_FlushFifo(EXAMPLE_DSPI_MASTER_BASEADDR, true, true);
DSPI_StopTransfer(EXAMPLE_DSPI_SLAVE_BASEADDR);
DSPI_DisableInterrupts(EXAMPLE_DSPI_SLAVE_BASEADDR, (uint32_t)kDSPI_AllInterruptEnable);
DSPI_FlushFifo(EXAMPLE_DSPI_SLAVE_BASEADDR, true, true);
/*Calculate the command and lastCommand*/
commandStruct.whichPcs =
(dspi_which_pcs_t)(1U << ((masterXfer.configFlags & DSPI_MASTER_PCS_MASK) >> DSPI_MASTER_PCS_SHIFT));
commandStruct.isEndOfQueue = false;
commandStruct.clearTransferCount = false;
commandStruct.whichCtar =
(dspi_ctar_selection_t)((masterXfer.configFlags & DSPI_MASTER_CTAR_MASK) >> DSPI_MASTER_CTAR_SHIFT);
commandStruct.isPcsContinuous =
(0U != (masterXfer.configFlags & (uint32_t)kDSPI_MasterPcsContinuous)) ? true : false;
command = DSPI_MasterGetFormattedCommand(&(commandStruct));
commandStruct.isEndOfQueue = true;
commandStruct.isPcsContinuous =
(0U != (masterXfer.configFlags & (uint32_t)kDSPI_MasterActiveAfterTransfer)) ? true : false;
lastCommand = DSPI_MasterGetFormattedCommand(&(commandStruct));
DSPI_SetFifoEnable(EXAMPLE_DSPI_MASTER_BASEADDR,false,false);
DSPI_SetFifoEnable(EXAMPLE_DSPI_SLAVE_BASEADDR,false,false);
/*Calculate the bitsPerFrame*/
bitsPerFrame = (uint8_t)(((EXAMPLE_DSPI_MASTER_BASEADDR->CTAR[commandStruct.whichCtar] & SPI_CTAR_FMSZ_MASK) >> SPI_CTAR_FMSZ_SHIFT) + 1U);
tmpMCR = EXAMPLE_DSPI_MASTER_BASEADDR->MCR;
if ((0U != (tmpMCR & SPI_MCR_DIS_RXF_MASK)) || (0U != (tmpMCR & SPI_MCR_DIS_TXF_MASK)))
{
fifoSize = 1U;
}
else
{
fifoSize = FSL_FEATURE_DSPI_FIFO_SIZEn(EXAMPLE_DSPI_MASTER_BASEADDR);
}
fifoSize=1U;