cancel
Showing results for 
Search instead for 
Did you mean: 

Is there anaybody that have a TIM triggered DMA working Code?

franck2
Associate II
Posted on December 01, 2014 at 22:49

I'm stuck on TIM triggered DMA to SPI.

My DMA Code configuration is as follow:

void DMA_Configuration(void)

 {

     DMA_InitTypeDef               DMA_InitStructure;

    

     /* Enable DMA1 clock */

   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

    

     /* Blank DMA Configuration */

     DMA_DeInit(DMA1_Channel1);      

    

     /* Using the default values at Startup */

     DMA_StructInit(&DMA_InitStructure);            

   /*Changes from the default values */    

     DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(SPI2->DR);            // Address of peripheral the DMA must map to => SPI2 Data Register

   DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) TTxBuffer;                // Variable to which received data will be stored

     DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;                           // Direction of transfer Memory to Peripheral =Destinatary

   DMA_InitStructure.DMA_BufferSize = 32;                                       // BufferSize

   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;             // We don't want to change the SPI2 Data register

   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;                      // We increment Memory

   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;      // We define Peripheral Data Size as Byte

   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;              // We define Memory Data Size as Byte

   DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;                              // Circular Mode define

   DMA_InitStructure.DMA_Priority = DMA_Priority_High;                          // High Priority

   DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;                                 // Memory to Memory Disable

    

      /* Initialize the DMA */

     DMA_Init(DMA1_Channel1, &DMA_InitStructure);           

    

     /* Enable the DMA transfer half and complete interrupt */

     DMA_ITConfig(DMA1_Channel1, DMA_IT_HT, ENABLE);                               // Half Transfer Interrupt Enable

   DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);                                 // Full transfer Interrupt Enable

    

     /* Enable the DMA TIM Triggered */

     TIM_DMACmd(TIM2, TIM_DMA_Trigger, ENABLE);

     TIM_DMACmd(TIM2, TIM_DMA_Update, ENABLE);

    

     /* Enable DMA1 Channel1 */

     DMA_Cmd(DMA1_Channel1, ENABLE);

 }

Looking at DMA_CCR1 gives me 0x2AB7 which is ok.

Looking at the SPI2_DR I found no value ; i.e. 0

Franck
24 REPLIES 24
franck2
Associate II
Posted on December 12, 2014 at 18:35

DMA_InitStructure.DMA_BufferSize = 2; // 2x 16-bit words, 1x 32-bit word, check endian/ordering
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; // The register is 16-bit wide
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
franck2
Associate II
Posted on December 15, 2014 at 09:51

Hi Clive,

The greatest experience in life: Sharing knowledge!

Thanks again Clive! Many thanks!

franck2
Associate II
Posted on December 17, 2014 at 11:56

Is there any way to add to that code a one pulse generation synchronized with TIM1?

I would like to have a pulse every 3.5*freq(TIM1)=delay and pulse time=0.5*Period(TIM1).

I attached a figure of what is needed.

Thanks in advance.

________________

Attachments :

TIM2_pulse.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I16v&d=%2Fa%2F0X0000000biU%2FiIuaT4.99Yk2prcorjRg9s5qlslndEr2d84m4W7AjJ4&asPdf=false
franck2
Associate II
Posted on December 17, 2014 at 15:03

My unsuccessful added code:

 /* Select the Master Slave Mode */

 

  TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable);

 

 

  /* Master Mode selection */

 

  TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update);    

 

    

 

 /* Slaves Configuration: PWM1 Mode */

 

  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

 

  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

 

  TIM_OCInitStructure.TIM_Pulse = Period / 2;

 

 

  TIM_OC1Init(TIM2 , &TIM_OCInitStructure);

 

 

  /* Slave Mode selection: TIM2 */

 

  TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Gated);

 

  TIM_SelectInputTrigger(TIM2, TIM_TS_ITR1);

I have define TIM2 CH1 at PA0 of my nucleo board STM32F302R8T6 as follow:

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ; // TIM2_CH1 (PA0)

 

  GPIO_Init(GPIOA, &GPIO_InitStructure);

 

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_1); // TIM2_CH1 PA0 AF1