If I call:
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)getADCBuffer, adcBufferLength); //uint16_t getADCBuffer[adcBufferLength] and adcBufferLenght is defined as 1000
and then call:
before the "adcBufferLength" was reached, how can I check how many new bytes I have in my getADCBuffer for every iteration of the code?
Can I do this:
adcNumSamplesCaptured = (adcBufferLength - (uint16_t)(DMA1_Channel1->CNDTR));
where obviously DMA1_Channel1 is associated with the ADC Configuration.
In normal mode, will CNDTR return to "adcBufferLength" automatically every time? The Reference Manual for my MCU says:
"If the channel is configured in non-circular mode, no DMA request is served after the last
transfer (that is once the number of data items to be transferred has reached zero). In order
to reload a new number of data items to be transferred into the DMA_CNDTRx register, the
DMA channel must be disabled. "
I should never reach "0" items left to transfer, is there something that I must do?
Should I call "CLEAR_BIT(DMA1_Channel1->CCR,DMA_CCR_EN);" before calling
"HAL_ADC_Start_DMA(&hadc1, (uint32_t*)getADCBuffer, adcBufferLength);" ?
I find that sometimes "adcNumSamplesCaptured is larger than the number of non-zero bytes in "getADCBuffer", and can't quite figure out why.
My ADC DMA Configuration:
/* ADC1 DMA Init */
/* ADC1 Init */
hdma_adc1.Instance = DMA1_Channel1;
hdma_adc1.Init.Request = DMA_REQUEST_0;
hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_adc1.Init.Mode = DMA_NORMAL;
hdma_adc1.Init.Priority = DMA_PRIORITY_HIGH;
if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)