cancel
Showing results for 
Search instead for 
Did you mean: 

STM32l152c Discovery board, DMA Stops after reading correct number of ADC values, would like to start again

julian2399
Associate II
Posted on September 28, 2015 at 16:08

Change my code now to use multiple channels and added in DMA.

If I ask the DMA to give me 4 sample from 3 channels, I get the 12 samples, whats the correct way to get the DMA to start again

void DMA1_Channel1_IRQHandler(void)
{
if( DMA_GetITStatus(DMA1_IT_TC1)) {
DMA_ClearITPendingBit(DMA1_IT_GL1);
}
}

Dma setup

/* Configuration ------------------------------------------------------*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
//reset DMA1 channe1 to default values;
DMA_DeInit(WHICH_DMA_CHANNEL);
//channel will be used for memory to memory transfer
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
//setting normal mode (non circular)
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
//medium priority
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
//source and destination data size word=32bit
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
//automatic memory destination increment enable.
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
//source address increment disable
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
//Location assigned to peripheral register will be source
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
//chunk of data to be transfered
DMA_InitStructure.DMA_BufferSize = setup->adc_setups * 8;
//source and destination start addresses
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(ADC1->DR);
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)adc1_read_value;
//send values to DMA registers
DMA_Init(WHICH_DMA_CHANNEL, &DMA_InitStructure);
// Enable DMA1 Channel Transfer Complete interrupt
DMA_ITConfig(WHICH_DMA_CHANNEL, DMA_IT_TC, ENABLE);
//Enable the WHICH_DMA
DMA_Cmd(WHICH_DMA_CHANNEL, ENABLE);
//Enable channel IRQ Channel */
NVIC_InitStructure.NVIC_IRQChannel = WHICH_DMA_CHANNEL_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
WHICH_DMA is DMA1
WHICH_DMA_CHANNEL is DMA1_Channel1
WHICH_DMA_CHANNEL_IRQn is DMA1_Channel1_IRQn

Now I get the IRQ once and would like to start it again. ADC has the following

ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

joolz
3 REPLIES 3
Posted on September 28, 2015 at 18:39

You want it to restart immediately, or some time in the future.

The former, use circular DMA, the latter you're going to have reconfigure the DMA and ADC. You'll want to separate the NVIC/Clock stuff, so you can minimize the work required in subsequent restarts. You'll likely have to reset the ADC to get things back in sync.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
julian2399
Associate II
Posted on September 29, 2015 at 10:16

to be honest a restart once i have read the values will suffice, so i need to set them up again, without the NVIC stuff

julian2399
Associate II
Posted on September 29, 2015 at 10:17

Just noticed I do have the DMA as circular but I only get 1 interrupt

joolz