cancel
Showing results for 
Search instead for 
Did you mean: 

SPI-Slave with DMA Rx & Tx channel

heiko239955
Associate
Posted on June 26, 2008 at 10:59

SPI-Slave with DMA Rx & Tx channel

1 REPLY 1
heiko239955
Associate
Posted on May 17, 2011 at 09:54

Anyone know how to configure DMA-controller and SSP0 in Slave-Mode to use DMA for Tx & Rx synchronous?

I'll try to communicate with a SPI-Master and want to use DMA to transfer the Data between SSP0 and memory.

SPI-communication seems to work. I'll see communication on a oscilloscope.

If I use DMA, I receive correct data. But the transmit data is shifted about 8 Bytes.

Here is the DMA configuration:

void DMA_Configuration(void)

{

DMA_StructInit(&DMA_InitStructChannel0);

DMA_StructInit(&DMA_InitStructChannel1);

DMA_DeInit();

DMA_Cmd(ENABLE);

DMA_SyncConfig((TUINT16)(DMA_SSP0_TX_Mask | DMA_SSP0_RX_Mask), ENABLE);

/* DMA Channel 0 */

DMA_StructInit(&DMA_InitStructChannel0);

DMA_InitStructChannel0.DMA_Channel_LLstItm = 0; /*No linked lists used*/

DMA_InitStructChannel0.DMA_Channel_SrcAdd = (TUINT32)(&SSP0->DR); /*Source address*/

DMA_InitStructChannel0.DMA_Channel_DesAdd = (TUINT32)&Test_SspRcvProfiBuf.SspRcvbytes[0]; /*Destination address*/

DMA_InitStructChannel0.DMA_Channel_SrcWidth = DMA_SrcWidth_Byte; /*Source width of one byte*/

DMA_InitStructChannel0.DMA_Channel_DesWidth = DMA_DesWidth_Byte; /*Destination width of one byte*/

DMA_InitStructChannel0.DMA_Channel_DesBstSize= DMA_DesBst_4Data; /* Initialize The Burst Size for the Destination */

DMA_InitStructChannel0.DMA_Channel_FlowCntrl = DMA_FlowCntrl2_DMA; /*The flow controller is the DMAC, Transfer Type: Peripheral-to-memory */

DMA_InitStructChannel0.DMA_Channel_Src = DMA_SRC_SSP0_RX;

DMA_InitStructChannel0.DMA_Channel_TrsfSize = 183; /*Transfer size */

DMA_ChannelDESIncConfig (DMA_Channel0, ENABLE); /*We increment the destination not the source*/

DMA_ITConfig(DMA_Channel0, ENABLE); /*Enable the Terminal Count interrupt*/

DMA_ITMaskConfig(DMA_Channel0, (TUINT16)DMA_ITMask_ITC, ENABLE);

DMA_Init(DMA_Channel0, &DMA_InitStructChannel0);

/* DMA Channel 1 */

DMA_StructInit(&DMA_InitStructChannel1);

DMA_InitStructChannel1.DMA_Channel_LLstItm = 0; /*No linked lists used*/

DMA_InitStructChannel1.DMA_Channel_SrcAdd = (TUINT32)&Test_SspSndProfiBuf.SspSndbytes[0]; /*Source address*/

DMA_InitStructChannel1.DMA_Channel_DesAdd = (TUINT32)((&SSP0->DR)); /*Destination address*/

DMA_InitStructChannel1.DMA_Channel_SrcWidth = DMA_SrcWidth_Byte; /*Source width of one byte*/

DMA_InitStructChannel1.DMA_Channel_DesWidth = DMA_DesWidth_Byte; /*Destination width of one byte*/

DMA_InitStructChannel1.DMA_Channel_SrcBstSize= DMA_SrcBst_4Data; /* Initialize The Burst Size for the Source*/

DMA_InitStructChannel1.DMA_Channel_FlowCntrl = DMA_FlowCntrl1_DMA; /*The flow controller is the DMAC, Transfer Type: Memory-to-peripheral */

DMA_InitStructChannel1.DMA_Channel_Des = DMA_DES_SSP0_TX;

DMA_InitStructChannel1.DMA_Channel_TrsfSize = 183; /*Transfer size */

DMA_ChannelSRCIncConfig (DMA_Channel1, ENABLE); /*We increment the source not the destination*/

DMA_ITConfig(DMA_Channel1, ENABLE); /*Enable the Terminal Count interrupt*/

DMA_ITMaskConfig(DMA_Channel1, (TUINT16)DMA_ITMask_ITC, ENABLE);

DMA_Init(DMA_Channel1, &DMA_InitStructChannel1);

}

Here the SSP0 configuration:

void SSP0_Configuration(void)

{

SSP_InitTypeDef SSP_InitStructure; /* Init-Struct der SSP */

TUINT32 k;

SSP_DeInit(SSP0);

SSP_StructInit(&SSP_InitStructure);

/* SSP0 initialization */

SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola;

SSP_InitStructure.SSP_Mode = SSP_Mode_Slave;

SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; /* CPOL = 0 */

SSP_InitStructure.SSP_CPHA = SSP_CPHA_2Edge; /* CPHA = 1 */

SSP_InitStructure.SSP_DataSize = SSP_DataSize_8b;

SSP_InitStructure.SSP_SlaveOutput = SSP_SlaveOutput_Enable;

SSP_Init(SSP0, &SSP_InitStructure);

/*Enable SSP0 DMA request*/

SSP_DMACmd(SSP0, (TUINT16)SSP_DMA_Transmit, ENABLE);

SSP_DMACmd(SSP0, (TUINT16)SSP_DMA_Receive, ENABLE);

/* SSP0 enable */

SSP_Cmd(SSP0, ENABLE);

}

DMA Transfer is started in an ISR for an external IRQ, which is parallel connected to NSS from SSP0 (chip select).

Thanks in advance

Heiko

[ This message was edited by: heikomasiero on 26-06-2008 14:54 ]

[ This message was edited by: heikomasiero on 26-06-2008 14:55 ]