AnsweredAssumed Answered

STM32F4: TIM Triggered SPI Transmit

Question asked by tom on May 13, 2013
Latest reply on Jul 24, 2013 by mercury
Hi,

I am trying to interface the STM32F4Discovery board with an external A/D-converter. The A/D generates a GPIO interrupt as soon as the data is sampled and ready to be retrieved. After that 3 * 8 bytes have to be retrieved over SPI. To read the data out of the ADC I ofcourse have to send dummy bytes so the clock is generated.

Now, I mapped the GPIO (PE9) to the TIM1 Ch1 and it is properly generating DMA requests on DMA2 Stream 1 Channel 6 to start the DMA transfer.
The DMA, after it is triggered by TIM1 CH1 CC1, should send out all data in the buffer, but it only sends out one single 8 bit or 16 bit sequence (depending on SPI definition). According to the reference manual, the Tx Buffer is only one word, so my worst case guess is that what I am intending on doing is impossible. Anyway, here are some parts of the code, maybe somebody can help me on this :)

TIM1 initialization
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_ICInit(TIM1, &TIM_ICInitStructure);
 
TIM_TIxExternalClockConfig (TIM1, TIM_TS_TI1FP1, TIM_ICPolarity_Rising, 0) ;
TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_External1);
 
TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE);
   
TIM_DMACmd(TIM1,TIM_DMA_CC1,ENABLE);
TIM_Cmd (TIM1, ENABLE);

SPI DMA with TIM DMA request
DMA_InitStructureTIM.DMA_BufferSize = 24 ;
DMA_InitStructureTIM.DMA_FIFOMode = DMA_FIFOMode_Disable ;
DMA_InitStructureTIM.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ;
DMA_InitStructureTIM.DMA_MemoryBurst = DMA_MemoryBurst_Single ;
DMA_InitStructureTIM.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructureTIM.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructureTIM.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructureTIM.DMA_PeripheralBaseAddr =(uint32_t) (&(SPIx->DR)) ;
DMA_InitStructureTIM.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_InitStructureTIM.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructureTIM.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructureTIM.DMA_Priority = DMA_Priority_High;
/* Configure TX DMA */
 
   
DMA_InitStructureTIM.DMA_Channel = TIM1CC1_DMA_CHANNEL ;
DMA_InitStructureTIM.DMA_DIR = DMA_DIR_MemoryToPeripheral ;
DMA_InitStructureTIM.DMA_Memory0BaseAddr =(uint32_t)aTxBuffer ;
DMA_Init(TIM1CC1_DMA_STREAM, &DMA_InitStructureTIM);

Thanks!

Outcomes