本帖最后由 sun0727 于 2017-9-13 03:15 编辑
设想的是这样的
ADC1 作为 MasterADC 控制如下 5 路, 结果依次付给 数组 的 0-4 低16位:
ADC1_IN1 -------> ADCConvertedData[0] 低16位
ADC1_IN2 -------> ADCConvertedData[1] 低16位
ADC1_IN3 ------> ADCConvertedData[2] 低16位
ADC1_IN4 ------> ADCConvertedData[3] 低16位
ADC1_IN12-----> ADCConvertedData[4] 低16位
ADC2 作为 SlaveADC 控制如下 3 路, 结果依次付给 数组 的 0-2 的高16位:
ADC2_IN1-------> ADCConvertedData[0] 高16位
ADC2_IN3-------> ADCConvertedData[1] 高16位
ADC2_IN4-------> ADCConvertedData[2] 高16位
但是经过我自己的编写,发现 ADC1 能扫描,但是 ADC2 结果在数组中的位置并不固定,原因是因为 ADC2 下的通道是 3 个 ,ADC1 的通道是 5 个 数量不对称 请问程序如何修改
以下是我的部分配置
DMA 配置
DMA_HandleTypeDef ADC1_DMA_Handle;
void ADC1_DMA_Init(ADC_HandleTypeDef* hadc)
{
ADC1_DMA_Handle.Instance = DMA1_Channel1;
ADC1_DMA_Handle.Init.Direction = DMA_PERIPH_TO_MEMORY;
ADC1_DMA_Handle.Init.PeriphInc = DMA_PINC_DISABLE;
ADC1_DMA_Handle.Init.MemInc = DMA_MINC_ENABLE;
ADC1_DMA_Handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
ADC1_DMA_Handle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
ADC1_DMA_Handle.Init.Mode = DMA_CIRCULAR;
ADC1_DMA_Handle.Init.Priority = DMA_PRIORITY_HIGH;
//HAL_DMA_DeInit(&ADC1_DMA_Handle);
HAL_DMA_Init(&ADC1_DMA_Handle);
__HAL_LINKDMA(hadc,DMA_Handle,ADC1_DMA_Handle);
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
}
多通道规则同步的配置
- void ADC_Multimode_Config(void)
- {
- ADC_Multimode.Mode = ADC_DUALMODE_REGSIMULT;
- ADC_Multimode.DMAAccessMode = ADC_DMAACCESSMODE_12_10_BITS;
- ADC_Multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_4CYCLES;
-
- HAL_ADCEx_MultiModeConfigChannel(&ADC1_Handle, &ADC_Multimode);
- }
复制代码 ADC1 的初始化
- void ADC1_Input_Init(void)
- {
- ADC1_Handle.Instance = ADC1;
- ADC1_Handle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; /* Synchronous clock mode, input ADC clock divided by 2*/
- ADC1_Handle.Init.Resolution = ADC_RESOLUTION_12B; /* 12-bit resolution for converted data */
- ADC1_Handle.Init.DataAlign = ADC_DATAALIGN_RIGHT; /* Right-alignment for converted data */
- ADC1_Handle.Init.ScanConvMode = ADC_SCAN_ENABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
- ADC1_Handle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */
- ADC1_Handle.Init.LowPowerAutoWait = DISABLE;
- ADC1_Handle.Init.ContinuousConvMode = ENABLE;
- ADC1_Handle.Init.NbrOfConversion = 5;
- ADC1_Handle.Init.DiscontinuousConvMode = DISABLE;
- ADC1_Handle.Init.ExternalTrigConv = ADC_SOFTWARE_START; /
- ADC1_Handle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /
- ADC1_Handle.Init.DMAContinuousRequests = ENABLE; /* ADC DMA continuous request to match with DMA circular mode */
- ADC1_Handle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
- HAL_ADC_Init(&ADC1_Handle);
-
- }
复制代码 ADC1 Channel 配置
- void ADC1_Channel_Config(void)
- {
- //common config for channel
-
- ADC1_sConfig.SamplingTime = ADC_SAMPLETIME_19CYCLES_5; /* Sampling time (number of clock cycles unit) */
- ADC1_sConfig.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */
- ADC1_sConfig.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
- ADC1_sConfig.Offset = 0;
-
- ADC1_sConfig.Channel = ADC_CHANNEL_1; /* Sampled channel number */
- ADC1_sConfig.Rank = ADC_REGULAR_RANK_1; /* Rank of sampled channel number ADCx_CHANNEL */
- HAL_ADC_ConfigChannel(&ADC1_Handle, &ADC1_sConfig);
-
- ADC1_sConfig.Channel = ADC_CHANNEL_2;
- ADC1_sConfig.Rank = ADC_REGULAR_RANK_2;
- HAL_ADC_ConfigChannel(&ADC1_Handle, &ADC1_sConfig);
-
- ADC1_sConfig.Channel = ADC_CHANNEL_3;
- ADC1_sConfig.Rank = ADC_REGULAR_RANK_3;
- HAL_ADC_ConfigChannel(&ADC1_Handle, &ADC1_sConfig);
-
- ADC1_sConfig.Channel = ADC_CHANNEL_4;
- ADC1_sConfig.Rank = ADC_REGULAR_RANK_4;
- HAL_ADC_ConfigChannel(&ADC1_Handle, &ADC1_sConfig);
-
- ADC1_sConfig.Channel = ADC_CHANNEL_12;
- ADC1_sConfig.Rank = ADC_REGULAR_RANK_5;
- HAL_ADC_ConfigChannel(&ADC1_Handle, &ADC1_sConfig);
- }
复制代码 ADC2 的初始化 和 Channel 配置
- void ADC2_Input_Init(void)
- {
- ADC2_Handle.Instance = ADC2;
-
- //HAL_ADC_DeInit(& ADC2_Handle);
- //HAL_ADCEx_Calibration_Start(&ADC2_Handle, ADC_SINGLE_ENDED);
-
- ADC2_Handle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; /* Synchronous clock mode, input ADC clock divided by 2*/
- ADC2_Handle.Init.Resolution = ADC_RESOLUTION_12B; /* 12-bit resolution for converted data */
- ADC2_Handle.Init.DataAlign = ADC_DATAALIGN_RIGHT; /* Right-alignment for converted data */
- ADC2_Handle.Init.ScanConvMode = ADC_SCAN_ENABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
- ADC2_Handle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */
- ADC2_Handle.Init.LowPowerAutoWait = DISABLE; /* Auto-delayed conversion feature disabled */
- ADC2_Handle.Init.ContinuousConvMode = ENABLE; /* Continuous mode enabled (automatic conversion restart after each conversion) */
- ADC2_Handle.Init.NbrOfConversion = 3; /* Parameter discarded because sequencer is disabled */
- ADC2_Handle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */
- ADC2_Handle.Init.NbrOfDiscConversion = 1; /* Parameter discarded because sequencer is disabled */
- //ADC2_Handle.Init.ExternalTrigConv = ADC_SOFTWARE_START; /* Software start to trig the 1st conversion manually, without external event */
- //ADC2_Handle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */
- ADC2_Handle.Init.DMAContinuousRequests = ENABLE; /* ADC DMA continuous request to match with DMA circular mode */
- ADC2_Handle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; /* DR register is overwritten with the last conversion result in case of overrun */
-
- HAL_ADC_Init(&ADC2_Handle);
-
- }
-
- //--------------------Configure the ADC2 Channel-----------------------------------
- void ADC2_Channel_Config(void)
- {
- //common config for channel
- ADC2_sConfig.SamplingTime = ADC_SAMPLETIME_19CYCLES_5; /* Sampling time (number of clock cycles unit) */
- ADC2_sConfig.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */
- ADC2_sConfig.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
- ADC2_sConfig.Offset = 0;
-
- ADC2_sConfig.Channel = ADC_CHANNEL_1; /* Sampled channel number */
- ADC2_sConfig.Rank = ADC_REGULAR_RANK_1; /* Rank of sampled channel number ADCx_CHANNEL */
- HAL_ADC_ConfigChannel(&ADC2_Handle, &ADC2_sConfig);
-
- ADC2_sConfig.Channel = ADC_CHANNEL_3;
- ADC2_sConfig.Rank = ADC_REGULAR_RANK_2;
- HAL_ADC_ConfigChannel(&ADC2_Handle, &ADC2_sConfig);
-
- ADC2_sConfig.Channel = ADC_CHANNEL_4;
- ADC2_sConfig.Rank = ADC_REGULAR_RANK_3;
- ADC2_sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
- HAL_ADC_ConfigChannel(&ADC2_Handle, &ADC2_sConfig);
-
- }
复制代码
函数的调用
#define ADC_CONVERTED_DATA_BUFFER_SIZE ((uint32_t) 5) /* Size of array aADCxConvertedData[] */
uint32_t aADCxConvertedData[ADC_CONVERTED_DATA_BUFFER_SIZE];
//------------------------------Start ADC in Dualmode and DMA --------------------------------------
void ADC_DMA_Dualmode_Start(void)
{
ADC1_Input_Init();
ADC_Multimode_Config();
ADC1_Channel_Config();
ADC2_Input_Init();
ADC2_Channel_Config();
//
//
HAL_ADC_Start(&ADC2_Handle);
HAL_ADCEx_MultiModeStart_DMA(&ADC1_Handle,(uint32_t *)aADCxConvertedData,ADC_CONVERTED_DATA_BUFFER_SIZE);
}
|
而接收到的数据只有12位,
是不是应该把高16位的数据,右移4位,
并把右移出来的部分,填充到低16位的高4位中呢?
写的有点拗口,希望能明白我在说什么。
评分
查看全部评分
求大神指点这种 数量非对称的 双重 ADC
评分
查看全部评分
handle.zip
2018-1-18 11:14 上传
点击文件名下载附件
下载积分: ST金币 -13.39 KB, 下载次数: 11, 下载积分: ST金币 -1
评分
查看全部评分
评分
查看全部评分
评分
查看全部评分
test_adc1.part02.rar
2020-3-5 15:04 上传
点击文件名下载附件
下载积分: ST金币 -15 MB, 下载次数: 0, 下载积分: ST金币 -1
test_adc1.part03.rar
2020-3-5 15:04 上传
点击文件名下载附件
下载积分: ST金币 -15 MB, 下载次数: 0, 下载积分: ST金币 -1
test_adc1.part04.rar
2020-3-5 15:04 上传
点击文件名下载附件
下载积分: ST金币 -15 MB, 下载次数: 0, 下载积分: ST金币 -1
test_adc1.part05.rar
2020-3-5 15:04 上传
点击文件名下载附件
下载积分: ST金币 -14.22 MB, 下载次数: 0, 下载积分: ST金币 -1
test_adc1.part01.rar
2020-3-5 15:05 上传
点击文件名下载附件
下载积分: ST金币 -15 MB, 下载次数: 0, 下载积分: ST金币 -1