STM32 双ADC同步注入转换模式,模块ADC2没有数据。
STM32G0B1CC单片机多个从板使用CAN链接,CAN接收帧和发送帧丢失的问题。
STM32G0B1adc+dma采样数据错位
cube stm32g030f6p6 adc analog watchdog1 无法配置
STM32H743+USB3300传输采集的数据前几次会丢包问题
STM32G070使用HAL_SPI_Receive函数疑问
stm32g030j6m6如何使用串口烧录程序?NRST引脚能否作为普通输入IO口用?
H750/743 VREFBUF配置问题
关于STM32F4的ADC测量不准确
与HAL_ADC_Start_DMA相关的一个十分怪异的问题
因为你现在要用到CH8 CH9 CH15,请把ADC扫描序列模式改为 Sequencer set to not fully configurable是应该的。
配置正确了,再来看看别的原因,是否哪里误会或忽视了。 这个ADC模块功能是没问题,包括我在内的很多
人都用了的。
别着急,一步步排查,相信你自己!
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.LowPowerAutoPowerOff = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion =1;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_12CYCLES_5;
hadc1.Init.OversamplingMode = ENABLE;
hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256; // 16bit
hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4;
hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_8;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_9;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK)
{
/* Calibration Error */
Error_Handler();
}
/* Start ADC conversion */
if (HAL_ADC_Start(&hadc1) != HAL_OK)
{
/* ADC conversion start error */
Error_Handler();
}
/* Wait for the first ADC conversion to be completed (timeout unit: ms) */
if (HAL_ADC_PollForConversion(&hadc1, 2) != HAL_OK)
{
/* ADC conversion start error */
Error_Handler();
}
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_SEQ_FIXED_BACKWARD;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.LowPowerAutoPowerOff = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion =1;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_12CYCLES_5;
hadc1.Init.OversamplingMode = ENABLE;
hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256; // 16bit
hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4;
hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_15;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK)
{
/* Calibration Error */
Error_Handler();
}
/* Start ADC conversion */
if (HAL_ADC_Start(&hadc1) != HAL_OK)
{
/* ADC conversion start error */
Error_Handler();
}
/* Wait for the first ADC conversion to be completed (timeout unit: ms) */
if (HAL_ADC_PollForConversion(&hadc1, 2) != HAL_OK)
{
/* ADC conversion start error */
Error_Handler();
}
你现在要用到CH8 CH9 CH15,请把ADC扫描序列模式改为 Sequencer set to not fully configurable,这样你
就用不着做配置来回切换。你不妨用CubeMx配置下, hadc1.Init.ScanConvMode = ADC_SCAN_SEQ_FIXED;
不瞒你说 还是真仿着ch8 ch9写的 改了一下模式
按照你的方法试了一下 ,ch8 和ch 9的值不正确,ch15正确
有可能只转换了最后的通道15 呢?
好的 ,我去试试看看,谢谢
uint16_t ADC_Read(uint32_t Channel)
{
uint32_t value;
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = Channel; /* 通道 */
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 2);
value=HAL_ADC_GetValue(&hadc1);
HAL_ADC_Stop(&hadc1);
return value;
}