Hello,
I'm using the SPI loopback example provided with the TI-RTOS , it works well.
but when I tried to use the same SPI " Board_SPI1 " in other task with the same priorirty , this error happened !!
" Error 2222 initializing SPI"
and the program is aborted !!
I thought that the SPI is gated with a mutex , isn't it ?
thanks in advance.
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
Void slaveTaskFxn (UArg arg0, UArg arg1)
{
SPI_Handle slaveSpi;
SPI_Params slaveSpiParams;
SPI_Transaction slaveTransaction;
UInt transferOK;
/* Initialize SPI handle with slave mode */
SPI_Params_init(&slaveSpiParams);
slaveSpiParams.mode = SPI_SLAVE;
slaveSpi = SPI_open(Board_SPI1, &slaveSpiParams);
if (slaveSpi == NULL) {
System_abort("Error1 initializing SPI\n");
}
else {
System_printf("SPI1 initialized\n");
}
/* Initialize slave SPI transaction structure */
slaveTransaction.count = SPI_MSG_LENGTH;
slaveTransaction.txBuf = (Ptr)slaveTxBuffer;
slaveTransaction.rxBuf = (Ptr)slaveRxBuffer;
/* Initiate SPI transfer */
transferOK = SPI_transfer(slaveSpi, &slaveTransaction);
if(transferOK) {
/* Print contents of slave receive buffer */
System_printf("Slave1: %s\n", slaveRxBuffer);
}
else {
System_printf("Unsuccessful slave1 SPI transfer");
}
/* Deinitialize SPI */
SPI_close(slaveSpi);
}
Void slave2TaskFxn (UArg arg0, UArg arg1)
{
SPI_Handle slaveSpi;
SPI_Params slaveSpiParams;
SPI_Transaction slaveTransaction;
UInt transferOK;
/* Initialize SPI handle with slave mode */
SPI_Params_init(&slaveSpiParams);
slaveSpiParams.mode = SPI_SLAVE;
slaveSpi = SPI_open(Board_SPI1, &slaveSpiParams);
if (slaveSpi == NULL) {
System_abort("Error 2222 initializing SPI\n");
}
else {
System_printf("SPI 222 initialized\n");
}
/* Initialize slave SPI transaction structure */
slaveTransaction.count = SPI_MSG_LENGTH;
slaveTransaction.txBuf = (Ptr)slaveTxBuffer;
slaveTransaction.rxBuf = (Ptr)slaveRxBuffer;
/* Initiate SPI transfer */
transferOK = SPI_transfer(slaveSpi, &slaveTransaction);
if(transferOK) {
/* Print contents of slave receive buffer */
System_printf("Slave2: %s\n", slaveRxBuffer);
}
else {
System_printf("Unsuccessful slave 222 SPI transfer");
}
/* Deinitialize SPI */
SPI_close(slaveSpi);
}
/*
* ======== masterTaskFxn ========
* Task function for master task.
*
* This task runs at a lower priority after the slave
* task to ensure it is ready for a transaction.
* Master SPI sends a message to slave and also
* receives message from slave. Task for this function
* is created statically. See the project's .cfg
* file.
*/
Void masterTaskFxn (UArg arg0, UArg arg1)
{
SPI_Handle masterSpi;
SPI_Transaction masterTransaction;
UInt transferOK;
/* Initialize SPI handle as default master */
masterSpi = SPI_open(Board_SPI0, NULL);
if (masterSpi == NULL) {
System_abort("Error initializing SPI\n");
}
else {
System_printf("SPI initialized\n");
}
/* Initialize master SPI transaction structure */
masterTransaction.count = SPI_MSG_LENGTH;
masterTransaction.txBuf = (Ptr)masterTxBuffer;
masterTransaction.rxBuf = (Ptr)masterRxBuffer;
/* Initiate SPI transfer */
transferOK = SPI_transfer(masterSpi, &masterTransaction);
if(transferOK) {
/* Print contents of master receive buffer */
System_printf("Master: %s\n", masterRxBuffer);
}
else {
System_printf("Unsuccessful master SPI transfer");
}
/* Deinitialize SPI */
SPI_close(masterSpi);
System_printf("Done\n");
System_flush();
/*
* Spin to avoid SDOCM00105002 "TI-RTOS examples with no heap get an error
* if they call BIOS_exit"
*/
while(true);
}