2016-06-27 08:02 AM
I am trying to transfer data to spi using timer 3 as a time base.
Timer 3 works fine. Than I am using : DMA1 Stream2 Channel5 to trigger memory to SPI2->DR transfers, with no joy.//TIMER 3 CHANNEL 4 UPDATE
hdma_tim3_ch4_up.Instance = DMA1_Stream2; hdma_tim3_ch4_up.Init.Channel = DMA_CHANNEL_5; hdma_tim3_ch4_up.Init.Direction = DMA_MEMORY_TO_PERIPH; hdma_tim3_ch4_up.Init.PeriphInc = DMA_PINC_DISABLE; hdma_tim3_ch4_up.Init.MemInc = DMA_MINC_DISABLE; hdma_tim3_ch4_up.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_tim3_ch4_up.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_tim3_ch4_up.Init.Mode = DMA_CIRCULAR; hdma_tim3_ch4_up.Init.Priority = DMA_PRIORITY_LOW; hdma_tim3_ch4_up.Init.FIFOMode = DMA_FIFOMODE_DISABLE; HAL_DMA_Init(&hdma_tim3_ch4_up); /* Several peripheral DMA handle pointers point to the same DMA handle. Be aware that there is only one stream to perform all the requested DMAs. */ __HAL_LINKDMA(htim_base,hdma[TIM_DMA_ID_CC4],hdma_tim3_ch4_up); __HAL_LINKDMA(htim_base,hdma[TIM_DMA_ID_UPDATE],hdma_tim3_ch4_up); /**MAIN.c*********************/ DMA_HandleTypeDef hdma_tim3_ch4_up; HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_4); //start timer 4, works HAL_DMA_Start_IT(&hdma_tim3_ch4_up, (uint32_t*)&SV.fields.internal_current, (uint32_t*)(&(SPI2->DR)), 1);__HAL_TIM_ENABLE_DMA(&htim3, TIM_DMA_UPDATE); //TIM1 trigger DMA transfer
Still no data on the spi bus.2016-06-27 10:42 AM
__HAL_LINKDMA(htim_base,hdma[TIM_DMA_ID_CC4],hdma_tim3_ch4_up);
__HAL_LINKDMA(htim_base,hdma[TIM_DMA_ID_UPDATE],hdma_tim3_ch4_up);
Decide if you are using UPDATE or CC4 (CHANNEL 4) as the trigger, you get to pick ONE, then apply consistently
2016-06-28 08:42 AM
Thanks Clive,
it works like a charm. The combination of PWM generation on CH1 and fine delay generation with the update event allows for /CS generation on the SPI Bus. Fabio2016-07-01 03:09 PM
Hi Fabio,
I'm trying to control SPI writes using a timer as well. Can you post the complete working code?-Pat