Hi,
I am currently working on CC3200 rev3.2 board. I want interface cc3200 with Davinci-dm365 board through SPI interface, where cc3200 acts as a slave and dm365 is a Master.
I have done it successfully using interrupt mode.
Now I enabled DMA channels for SPI transactions, as below
#define MASTER_MODE 0
#define TR_BUFF_SIZE 38
//*****************************************************************************
// Global variables
//*****************************************************************************
static unsigned char g_ucTxBuff[TR_BUFF_SIZE]="This is CC3200 SPI Slave Application writing to Mcam-board\n\r";
static unsigned char g_ucRxBuff[TR_BUFF_SIZE];
BoardInit();
//
// Initialize uDMA
//
UDMAInit();
//
// Muxing UART and SPI lines.
//
PinMuxConfig();
//
// Enable the SPI module clock
//
MAP_PRCMPeripheralClkEnable(PRCM_GSPI,PRCM_RUN_MODE_CLK);
//
// Initialising the Terminal.
//
InitTerm();
//
// Clearing the Terminal.
//
ClearTerm();
//
// Display the Banner
//
Message("\n\n\n\r");
Message("\t\t ********************************************\n\r");
Message("\t\t CC3200 SPI Demo Application \n\r");
Message("\t\t ********************************************\n\r");
Message("\n\n\n\r");
//
// Reset the peripheral
//
MAP_PRCMPeripheralReset(PRCM_GSPI);
//
// Reset SPI
//
MAP_SPIReset(GSPI_BASE);
//
// Configure SPI interface
//
MAP_SPIConfigSetExpClk(GSPI_BASE,MAP_PRCMPeripheralClockGet(PRCM_GSPI),
SPI_IF_BIT_RATE,SPI_MODE_SLAVE,SPI_SUB_MODE_0,
(SPI_HW_CTRL_CS |
SPI_4PIN_MODE |
SPI_TURBO_OFF |
SPI_CS_ACTIVELOW |
SPI_WL_8));
//
// Enable SPI for communication
//
MAP_uDMAChannelAssign( UDMA_CH30_GSPI_RX);
MAP_uDMAChannelAssign( UDMA_CH31_GSPI_TX );
//
// Register Interrupt Handler
//
MAP_SPIIntRegister(GSPI_BASE,SlaveIntHandler);
MAP_SPIEnable(GSPI_BASE);
//
// Enable Interrupts. dma will cause intr on completion of transfer
//
MAP_SPIIntEnable(GSPI_BASE,SPI_INT_DMATX);
MAP_SPIIntEnable(GSPI_BASE,SPI_INT_DMARX);
//
// Configure the control parameters for the spi TX. The uDMA spi TX
// channel is used to transfer a block of data from a buffer to the tx-reg.
// The data size is 8 bits. The source address increment is 8-bit bytes
// since the data is coming from a buffer. The destination increment is
// none since the data is to be written to the spi data register. The
// arbitration size is set to 1,
//
SetupTransfer(UDMA_CH30_GSPI_RX | UDMA_PRI_SELECT,
UDMA_MODE_BASIC,
sizeof(g_ucRxBuff),
UDMA_SIZE_8,
UDMA_ARB_1,
(void *)(GSPI_BASE + MCSPI_O_RX0),
UDMA_SRC_INC_NONE,
g_ucRxBuff, UDMA_DST_INC_8);
SetupTransfer(UDMA_CH31_GSPI_TX| UDMA_PRI_SELECT,
UDMA_MODE_BASIC,
sizeof(g_ucTxBuff),
UDMA_SIZE_8,
UDMA_ARB_1,
g_ucTxBuff,
UDMA_SRC_INC_8,
(void *)(GSPI_BASE + MCSPI_O_TX0),
UDMA_DST_INC_NONE);
MAP_SPIDmaEnable(GSPI_BASE, SPI_RX_DMA | SPI_TX_DMA);
//
// Print mode on uart
//
Message("(DMA) Enabled SPI Interface in Slave Mode\n\rReceived : ");
Here I'm facing Two main problems
1> interrupt handler should be called after a total number of bytes transferred by DMA channel, to indicate transfer was done.
but sometimes, when I run the program interrupt handler is getting called immediately, and indicating DMA receive channel is in STOP mode, which occures after total number of transfers. it is happening though the Master is idle (No clock given to slave).
2> sometimes interrupt is not called immediately, but called after total byte transfers by DMA, which is desired.
in this case Master receiving the data sent by slave, but slave is not receiving any data. I put a print inside receive channel stop condition.
Handler is written as follows.
static void SlaveIntHandler()
{
unsigned long ulMode;
Message("Slave hndlr\n");
ulMode = MAP_uDMAChannelModeGet(UDMA_CH30_GSPI_RX | UDMA_PRI_SELECT);
if(ulMode == UDMA_MODE_STOP)
{
Message("Rx done and data received is:\n");
Report("%s\n\r",g_ucRxBuff);
MAP_SPIDmaDisable(GSPI_BASE, SPI_RX_DMA);
}
ulMode = MAP_uDMAChannelModeGet(UDMA_CH31_GSPI_TX | UDMA_PRI_SELECT);
if(ulMode == UDMA_MODE_STOP)
{
Message("Tx done\n\r");
MAP_SPIDmaDisable(GSPI_BASE, SPI_TX_DMA );
}
}
Thank you,
VinodKumar.