Tool/software: Code Composer Studio
Hi,
I have currently configured an MSP432P4111 Launchpad as SPI master and MSP432P401R Launchpad as SPI Slave(both using ti rtos APIs).
I am attempting to recursively send same data from the SLAVE every time MASTER requests for a transfer.
The code seems to be permanently stuck at SPI_transfer(); . I am unable to perform other tasks on the slave device once it reaches the while(true) loop.
The other issue i have noticed is that the spi_transfer() is not entering the callback function.
Here is my code for SPI slave:
#include <stddef.h>
#include <stdint.h>
#include <string.h>
/* POSIX Header files */
#include <unistd.h>
/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/SPI.h>
#include <ti/display/Display.h>
/* Driver configuration */
#include "ti_drivers_config.h"
#define THREADSTACKSIZE (1024)
#define SPI_MSG_LENGTH (20)
#define MAX_LOOP (10)
static Display_Handle display;
unsigned char slaveRxBuffer[SPI_MSG_LENGTH];
unsigned char slaveTxBuffer[SPI_MSG_LENGTH];
//extern uint8_t HostResp_Packt[4];
int8_t start_transmission = 0;
unsigned char slave_message_1[] = "SLAVE_MSG1";
unsigned char slave_message_2[] = "SLAVE_MSG2";
unsigned char buffer_tx[20];
static void transferCallback(SPI_Handle handle, SPI_Transaction *transaction)
{
// Start another transfer
SPI_transfer(handle, transaction);
start_transmission = 1;
}
/*
* ======== slaveThread ========
* Slave SPI sends a message to master while simultaneously receiving a
* message from the master.
*/
void slaveThread()
{
SPI_Handle slaveSpi;
SPI_Params spiParams;
SPI_Transaction transaction;
bool transferOK;
SPI_init();
strcat(buffer_tx, slave_message_1);
strcat(buffer_tx, slave_message_2);
/*
* Open SPI as slave in callback mode; callback mode is used to allow us to
* configure the transfer & then set CONFIG_SPI_SLAVE_READY high.
*/
SPI_Params_init(&spiParams);
//spiParams.frameFormat = SPI_POL0_PHA1;
spiParams.mode = SPI_SLAVE;
spiParams.bitRate = 10000000;
//spiParams.transferTimeout = 5;
spiParams.transferMode = SPI_MODE_CALLBACK;
spiParams.transferCallbackFxn = transferCallback;
slaveSpi = SPI_open(CC_SPI_SLAVE, &spiParams);
if (slaveSpi != NULL)
{
/* Copy message to transmit buffer */
RESTART_TRANSACTION:
strncpy((char*) slaveTxBuffer, buffer_tx, SPI_MSG_LENGTH);
memset((void*) slaveRxBuffer, 0, SPI_MSG_LENGTH);
transaction.count = SPI_MSG_LENGTH;
transaction.txBuf = (void*) slaveTxBuffer;
transaction.rxBuf = (void*) slaveRxBuffer;
Display_printf(display, 0, 0, "Slave SPI initialized\n");
/*
* Setup SPI transfer; CONFIG_SPI_SLAVE_READY will be set to notify
* master the slave is ready.
*/
transferOK = SPI_transfer(slaveSpi, &transaction);
while(1){
if(transaction.status == SPI_TRANSFER_COMPLETED)
{
start_transmission = 0;
goto RESTART_TRANSACTION;
}
}
}
else
{
Display_printf(display, 0, 0, "Error initializing slave SPI\n");
}
SPI_close(slaveSpi);
}