AnsweredAssumed Answered

Want to trigger DMA from Timer

Question asked by fireout on Oct 14, 2015
Latest reply on Oct 17, 2015 by fireout
I am using the ST32f303.
I would like TIM4 to trigger the DMA which should move data from memory to SPI2.
Tim4 count is changing but it does not trigger the DMA. Can somebody please point out where I am going wrong - this is my first stm32 program

    TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);// Time Base configuration
    TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseStructure.TIM_Period = 0xffff;
    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
 
//setup the output compare
    TIM_OCStructInit(&TIM_OCInitStructure);
 
    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable;
    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
    TIM_OCInitStructure.TIM_Pulse = X_OFFSET;
    TIM_OC1Init(TIM4, &TIM_OCInitStructure);
 
  TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Disable);//??
  TIM_ARRPreloadConfig(TIM4, DISABLE); //??
      /* Slave Mode selection: TIM4 */
  TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Combined_ResetTrigger);
  TIM_SelectInputTrigger(TIM4, TIM_TS_ITR2);
     
         
    TIM_DMACmd(TIM4,TIM_DMA_CC1, ENABLE ); // Enable TIM1_CC1 DMA Requests

DMA_DeInit(DMA1_Channel1);//reset DMA1 channe1 to default values;
 
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//channel will be used for memory to SPI transfer
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;//setting normal mode (non circular)
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;//medium priority
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//source and destination data size word=32bit
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//automatic memory increment enable.
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;//Location assigned to peripheral register will be destination
DMA_InitStructure.DMA_BufferSize = COUNT_MAX;//chunk of data to be transfered
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&SPI2->DR;//source and destination start addresses
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Buffer;
 
DMA_Init(DMA1_Channel1, &DMA_InitStructure);//send values to DMA registers
 
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);// Enable DMA1 Channel Transfer Complete interrupt

Outcomes