Other Parts Discussed in Thread: AM3359, SYSBIOS, CODECOMPOSER
HEy together,
i have a problem with my SPI-Communication between a Sitara (AM3359) and a Concerto(F28M35). The Sitara is the SPI-Master. I think the problem is at the Sitara, because he stops the transmission after a couple of times. I transfer 3 Bytes per cycle.
The Code in the Sitara is:
The code in the main:
McSPIPinMuxConfig(MCSPI_INSTANCE_1);
McSPIInit(MCSPI_INSTANCE_1, 32, 0, MCSPI_MULTI_CH, MCSPI_CHANNEL_0);
Task_Params_init(&taskParams);
taskParams.priority = 1;
taskParams.instance->name = "OutputJ9";
taskParams.stackSize = 2048;
Task_create(outputJ9, &taskParams, NULL);
The code from the task (OutputJ9) in a endless do-while-loop:
void outputJ9(UArg arg0, UArg arg1)
{
unsigned char aktuellerZustand = 0;
static unsigned int spicnt = 0;
Semaphore_pend(switchReady, BIOS_WAIT_FOREVER);
Semaphore_post(switchReady);
do
{
//Send a random value over SPI to the concerto
if (++spicnt % 1000 == 0)
{
unsigned char buffer[SPI_MSG_LENGTH_extern];
LivecheckSPI_Sitara++;
if (LivecheckSPI_Sitara >= 254)
{
LivecheckSPI_Sitara = 0;
}
buffer[0] = 1;
buffer[1] = LivecheckSPI_Sitara;
buffer[2] = 2;
McSPICycle(MCSPI_INSTANCE_1, buffer, SPI_MSG_LENGTH_extern, MCSPI_CHANNEL_0);
char logText2[255];
sprintf(logText2, "Receive in char2: %d\n", buffer[0]);
UARTPutString(uartInstance, logText2);
char logText3[255];
sprintf(logText3, "Receive in char3: %d\n", buffer[1]);
UARTPutString(uartInstance, logText3);
char logText4[255];
sprintf(logText4, "Receive in char4: %d\n", (buffer[2]));
UARTPutString(uartInstance, logText4);
}
Task_sleep(1);
} while(1);
The code in the concerto is:
#include "SPI_Master_Slave.h"
extern Void slaveTaskFxn(UArg arg0, UArg arg1);
The code in the main of the m3:
Task_Handle taskHandle;
Task_Params taskParams;
Error_Block eb;
//static unsigned long ulMWRAllow;
/* Call board init functions */
Board_initGeneral();
Board_initEMAC();
SPI_Master_Slave_initSPI();
TMDXDOCKH52C1_initDMA();
/* Create SPI-Slave-task with priority 2 *///SW 27.01.2015
Task_Params_init(&taskParams);
taskParams.stackSize = 1024;
taskParams.priority = 2;
taskParams.instance->name = "slaveTask";
taskHandle = Task_create((Task_FuncPtr)slaveTaskFxn, &taskParams, &eb);
The code in the "slaveTask" is:
/* Allocate buffers in .dma section of memory for concerto devices */
#ifdef MWARE
#pragma DATA_SECTION(masterSpiRxBuffer, ".dma");
#pragma DATA_SECTION(masterSpiTxBuffer, ".dma");
#pragma DATA_SECTION(slaveSpiRxBuffer, ".dma");
#pragma DATA_SECTION(slaveSpiTxBuffer, ".dma");
#endif
UChar masterSpiRxBuffer[SPI_MSG_LENGTH_extern];
UChar masterSpiTxBuffer[SPI_MSG_LENGTH_extern]; // = "Hello, this is master SPI";
UChar slaveSpiRxBuffer[SPI_MSG_LENGTH_extern];
UChar slaveSpiTxBuffer[SPI_MSG_LENGTH_extern];// = "Hello, this is slave SPI";
int slaveSpiRxBufferINT[SPI_MSG_LENGTH_extern];
int LivecheckSPI_Concerto = 0;
* ======== SPI_Master_Slave_initSPI ========
*/
Void SPI_Master_Slave_initSPI(Void)
{
//independent from Master or Slave
// SSI0
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);//GPIO port D needs to be enabled so these pins can be used.
GPIOPinConfigure(GPIO_PD0_SSI0TX);
GPIOPinConfigure(GPIO_PD1_SSI0RX);
GPIOPinConfigure(GPIO_PD2_SSI0CLK);
GPIOPinConfigure(GPIO_PD3_SSI0FSS);
GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 |
GPIO_PIN_2 | GPIO_PIN_3);
System_printf("SPI_Master_Slave.c: Init SPI-Port successful\n");
SPI_init();
}
/*
* ======== slaveTaskFxn ========
Void slaveTaskFxn (UArg arg0, UArg arg1)
{
SPI_Handle slaveSpi;
SPI_Params slaveSpiParams;
SPI_Transaction slaveTransaction;
UInt transferOK;
slaveSpiTxBuffer[0] = 130;
slaveSpiTxBuffer[1] = 110;
slaveSpiTxBuffer[2] = 120;
/* Initialize SPI handle with slave mode */
SPI_Params_init(&slaveSpiParams);
slaveSpiParams.mode = SPI_SLAVE;
slaveSpi = SPI_open(Board_SPI0, &slaveSpiParams);
if (slaveSpi == NULL) {
System_abort("Error initializing SPI\n");
}
else {
System_printf("SPI Slave initialized\n");
}
/* Initialize slave SPI transaction structure */
slaveTransaction.count = SPI_MSG_LENGTH_extern;
slaveTransaction.txBuf = (Ptr)slaveSpiTxBuffer;
slaveTransaction.rxBuf = (Ptr)slaveSpiRxBuffer;
// Enable the SSI0 module.
SSIEnable(SSI0_BASE);
while(1)
{
slaveSpiTxBuffer[0] = LivecheckSPI_Concerto;
/* Initiate SPI transfer */
transferOK = SPI_transfer(slaveSpi, &slaveTransaction);
if(transferOK) {
/* Print contents of slave receive buffer */
System_printf("Slave: %s\n", slaveSpiRxBuffer);
slaveSpiRxBufferINT[0] = (int)slaveSpiRxBuffer[0];
System_printf("Slave0: %d\n", slaveSpiRxBufferINT[0]);
slaveSpiRxBufferINT[1] = (int)slaveSpiRxBuffer[1];
System_printf("Slave1: %d\n", slaveSpiRxBufferINT[1]);
slaveSpiRxBufferINT[2] = (int)slaveSpiRxBuffer[2];
System_printf("Slave2: %d\n", slaveSpiRxBufferINT[2]);
LivecheckSPI_Concerto++;
if (LivecheckSPI_Concerto >= 254)
{
LivecheckSPI_Concerto = 0;
}
}
else {
System_printf("Unsuccessful slave SPI transfer");
}
System_flush();
}
/* Deinitialize SPI */
SPI_close(slaveSpi);
}
/*
This was the code of the sitara and concerto. The transmission starts and send the 3 Bytes for a couple of times and then it stops! It is not every time the same position, sometimes after 9, sometimes after 35 successful transmissions. If i switch the sitara off and after 1 second on again, the transmission starts from the beginning and stops after a couple of time again!
I saw that, sometimes the livecheck is in the first and sometimes in the last byte, so i think there is a problem, that there are some bytes lost or to much.
Does anybody have an idea what the problem can be?
Maybe i have to initialize a FIFO in the sitara? Like:
McSPITxFIFOConfig(MCSPI_INSTANCE_1, MCSPI_TX_FIFO_ENABLE, MCSPI_CHANNEL_0);
McSPIRxFIFOConfig(MCSPI_INSTANCE_1, MCSPI_RX_FIFO_ENABLE, MCSPI_CHANNEL_0);
Or is the problem the "MCSPI_MULTI_CH" in the sitara? I think this mode means, that there wait more than 1 byte per cycle for the transmission!?
Can someone help me?
Regards,
Sebastian