Putting ADC data via DMA to upper 16 bit of 32 bit variable.
Hi
I sample analog data with the STM32F401CE ADC. 12 bit resolution. This data is stored via DMA in an array.
If I use a 16 bit array, everythin works fine.
I now want to shift the whole data 16 bit to the left.
Therefore I switched to a 32 bit data array to store the data. Also I changed the Data width in the DMA settings from "Half Word" to "Word". This also works fine, now the data is stored in 32 bit values. But it is not shifted.
Therefore I try to pass the DMA init function the starting address shifted by 16 bit, so the data is always stored in the "upper" 16 bit of the 32 bit values. It looks like:
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)(((uint16_t*)adc_buf)+1), (uint32_t)FFT_LENGTH*2);
The "+1" however has no effect. Changing to "+2" has the expected effect, that the first value of the adc_buf remains zero.
Here come my questions:
- how do I pass the starting address of the 32 bit write values to ensure writing to the upper value 16 bit of 32 bit values?
- Is there another solution to my problem, like shifting the ADC value by <<16 during DMA writing?
- Looping over the complete buffer after the data has beew written (and DMA IR has been triggered) and shifting every single value <<16 does not seem like a good solution as it takes too long - do you agree?
Thanks for your help,
BR Donald
PS: I added one value to the adc_buf length to not unintentionally overwrite some other data in the RAM.