2017-09-22 12:46 AM
Hi there,
i'm working on a STM32F103 MCU and I want to acquire 9 channels with ADC1.
With STM32Cube I configured the ADC1 in this way:
These is the channel list:
IN9
IN10
Also I configured the DMA to transfer the data from the ADC to a memory buffer.
To start the conversion I use:
HAL_ADC_Start_DMA( ADC1_ModuleHandler, ADC_1_Buffer, ADC_1_CH_MAX_VALUE )
Where:
ADC1_ModuleHandler: ADC Handler.
ADC_1_Buffer: uint32_t array with 9 elemets.
ADC_1_CH_MAX_VALUE: enum to identify the channel. It starts from 0 to 9.
The conversion works fine but into the ADC_1_Buffer only the first five elements contain a value different from 0. the other 4 elements contain 0.
Moreover if I convert to analog voltage the value of the first element ( Vref Int) I obtain 1.2V that correspond to the internal Vref. So I think that the ADC conversion works.
I don't know why only a subset of channels is converted.
Do I missing some configuration parameters?
Thanks in advance!
Federico
#dma-adc #scan-mode #stm32cubemx(hal) Note: this post was migrated and contained many threaded conversations, some content may be missing.2017-09-22 09:31 AM
Hello Fede.rico.
ADC_1_Buffer: uint32_t array with 9 elemets.
You defined the array as 32 bit, this means 36 Bytes size buffer.
The ADC-DMA uses only 2*9=18 bytes (the first 18).
Define 'array' as uint16_t array[9] and use cast inside HAL_ADC_Start_DMA(.) function.
Regards
vf
2017-09-26 04:51 AM
Hello Vangelis,
your solution doesn't work.
The acquired data sample are wrong.
My implementation work (only for the first 5 channel) in fact I can acquire the internal Vref and it's have the right value: 1.2 volts.
I dont' know why I cannot convert the other channel.
2017-09-26 08:11 AM
The ADC-DMA uses only 2*9=18 bytes (the first 18).
Define 'array' as uint16_t array[9] and use cast inside HAL_ADC_Start_DMA(.) function.
The DMA is configured for word access on the memory size, therefore it is not the issue here.
Rini.Federico
It may be that you check the buffer before the conversion has finished. What mechanism do you use to check that the conversion sequence finished? The conversion complete callback?Another possibility to check is that no overrun or other occurs in either the ADC or in the DMA. You should check their status registers after the conversion sequence.
2017-09-26 08:22 AM
Hello Ben K,
yes I use the 'HAL_ADC_ConvHalfCpltCallback' when the DMA transfer is complete. The conversion seems good because the value of other channel is correct.
2017-09-26 08:32 AM
Okay, so you use the conversion HALF complete callback, which is triggered by the DMA interrupt for finishing half of its total transfer. You should use the 'HAL_ADC_ConvCpltCallback' instead.
2017-09-26 08:35 AM
Ok! Now I understand.
If I use Half conversion is it true that only the first half of my array is filled. Am I Right?
I tried to use the 'HAL_ADC_ConvCpltCallback' but now the values inside my buffer are wrong!
2017-09-26 08:46 AM
fede.rico wrote:
Ok! Now I understand.
If I use Half conversion is it true that only the first half of my array is filled. Am I Right?
Correct. The half transfer complete here means that half of the conversion sequence has been executed by the ADC, which triggers the DMA for each transfer. The DMA provides interrupt sources for Transfer Complete and Half Transfer complete signaling, both of these are redirected to the user peripheral's (in this case the ADC's) xCpltCallback and xHalfCpltCallback functions by the HAL.
2017-09-26 08:49 AM
Thanks for the explanation.
I tried to use the 'HAL_ADC_ConvCpltCallback' but now the values inside my buffer are wrong!
2017-09-26 09:14 AM
You need to be more specific than that, what makes you think that you have wrong values?