转自:http://blog.sina.com.cn/s/blog_6225307f0102wmhb.html
1,规则模式下,用户内存缓冲区的数据宽度需要和DMA设置的数据宽度一致,如下:
typedef struct rt_device_hwadc
{
struct rt_device parent;
const struct rt_hwadc_ops *ops;
uint8_t flag_adc_convert_complete;
__IO uint16_t adc_converted_value[TOTAL_CHANNELS];
}rt_device_hwadc_t;
hdma_adcx.Instance = ADC_DMAx_CHANNELn;
hdma_adcx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_adcx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_adcx.Init.MemInc = DMA_MINC_ENABLE;
hdma_adcx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_adcx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_adcx.Init.Mode = DMA_CIRCULAR;
hdma_adcx.Init.Priority = DMA_PRIORITY_HIGH;
HAL_DMA_Init(&hdma_adcx);
__HAL_LINKDMA(hadc,DMA_Handle,hdma_adcx);
2, 启动转换时连接DMA的通道数
HAL_ADC_Start_DMA(&(hwadc->adcHandle), (uint32_t *)buffer, TOTAL_CHANNELS)
其中buffer的数据类型是uint16_t*.
3,多通道顺序参数rank,
在配置rank时,如果配置的rank在开启的通道中不连续,DMA无法将转换的数据传到对应的缓冲区,也就和无法读取到该通道的数据。