static void master_task(void *pvParameters)
{
spi_master_config_t masterConfig;
spi_rtos_handle_t master_rtos_handle;
spi_transfer_t masterXfer = {0};
uint32_t sourceClock;
status_t status;
uint32_t errorCount;
uint32_t i;
NVIC_SetPriority(EXAMPLE_SPI_MASTER_IRQ, SPI_NVIC_PRIO + 1);
SPI_MasterGetDefaultConfig(&masterConfig);
masterConfig.baudRate_Bps = 500000;
masterConfig.sselNum = EXAMPLE_SPI_SSEL;
masterConfig.sselPol = (spi_spol_t)EXAMPLE_MASTER_SPI_SPOL;
//Rong wrote
masterConfig.delayConfig.preDelay=2;
masterConfig.delayConfig.postDelay =2;
masterConfig.delayConfig.frameDelay =2;
masterConfig.delayConfig.transferDelay =2;
///Rong writing ending
sourceClock = 12000000;
status = SPI_RTOS_Init(&master_rtos_handle, EXAMPLE_SPI_MASTER, &masterConfig, sourceClock);
if (status != kStatus_Success)
{
PRINTF("SPI master: error during initialization. \r\n");
vTaskSuspend(NULL);
}
/*Start master transfer*/
masterXfer.txData = masterSendBuffer;
//Wrong write:
masterXfer.dataSize = 1; //TRANSFER_SIZE;
//Rong wtiting ends
masterXfer.rxData = masterReceiveBuffer;
masterXfer.configFlags |= kSPI_FrameAssert;
status = SPI_RTOS_Transfer(&master_rtos_handle, &masterXfer);
PRINTF("Master transmited:");
for (i = 0; i < TRANSFER_SIZE; i++)
{
if (i % 8 == 0)
{
PRINTF("\r\n");
}
PRINTF("0x%2x ", masterSendBuffer[i]);
}
PRINTF("\r\n\r\n");
PRINTF("Slave received:");
for (i = 0; i < TRANSFER_SIZE; i++)
{
if (i % 8 == 0)
{
PRINTF("\r\n");
}
PRINTF("0x%2x ", slaveReceiveBuffer[i]);
}
PRINTF("\r\n\r\n");
PRINTF("Slave transmited:");
for (i = 0; i < TRANSFER_SIZE; i++)
{
if (i % 8 == 0)
{
PRINTF("\r\n");
}
PRINTF("0x%2x ", slaveSendBuffer[i]);
}
PRINTF("\r\n\r\n");
PRINTF("Master received:");
for (i = 0; i < TRANSFER_SIZE; i++)
{
if (i % 8 == 0)
{
PRINTF("\r\n");
}
PRINTF("0x%2x ", masterReceiveBuffer[i]);
}
PRINTF("\r\n\r\n");
if (status == kStatus_Success)
{
PRINTF("SPI master transfer completed successfully.\r\n");
}
else
{
PRINTF("SPI master transfer completed with error.\r\n");
}
errorCount = 0;
for (i = 0; i < TRANSFER_SIZE; i++)
{
if (masterReceiveBuffer[i] != slaveSendBuffer[i])
{
errorCount++;
}
}
if (errorCount == 0)
{
PRINTF("Slave-to-master data verified ok.\r\n");
}
else
{
PRINTF("Mismatch in slave-to-master data!\r\n");
}
vTaskSuspend(NULL);
}