采用hal库,多路采样,发现只要启动ad,ad输入就会莫名其妙有0.4V左右的电压。配置如下,
hadc.Instance = ADC1;
hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4 ;
hadc.Init.Resolution = ADC_RESOLUTION_12B;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.EOCSelection =ADC_EOC_SEQ_CONV;//
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
hadc.Init.ContinuousConvMode = ENABLE;//
hadc.Init.DiscontinuousConvMode =DISABLE;
hadc.Init.ExternalTrigConv =ADC_SOFTWARE_START;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.DMAContinuousRequests = ENABLE;
hadc.Init.Overrun =ADC_OVR_DATA_OVERWRITTEN;//
if (HAL_ADC_Init(&hadc) != HAL_OK)
{
Error_Handler(ERR_ADC_init);
}
__HAL_RCC_DMA1_CLK_ENABLE();
hdma_adc.Instance = DMA1_Channel1;
hdma_adc.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_adc.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_adc.Init.MemInc = DMA_MINC_ENABLE;
hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_adc.Init.Mode = DMA_CIRCULAR;
hdma_adc.Init.Priority = DMA_PRIORITY_MEDIUM;
if (HAL_DMA_Init(&hdma_adc) != HAL_OK)
{
Error_Handler(ERR_DMA_Init);
}
__HAL_DMA1_REMAP(HAL_DMA1_CH1_ADC);
__HAL_LINKDMA(&hadc,DMA_Handle,hdma_adc);
if (HAL_ADCEx_Calibration_Start(&hadc) != HAL_OK)
{
Error_Handler(ERR_ADCEx_Cal);
}
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank =ADC_RANK_CHANNEL_NUMBER;
sConfig.SamplingTime = ADC_SAMPLETIME_13CYCLES_5;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler(ERR_ADC_Config);
}
sConfig.Channel = ADC_CHANNEL_6;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler(ERR_ADC_Config);
}
sConfig.Channel = ADC_CHANNEL_7;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler(ERR_ADC_Config);
}
sConfig.Channel = ADC_CHANNEL_14;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler(ERR_ADC_Config);
}
sConfig.Channel = ADC_CHANNEL_15;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler(ERR_ADC_Config);
}
硬件io配置如下
__HAL_RCC_ADC1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/**ADC GPIO Configuration
PA0 ------> ADC_IN0
PA6 ------> ADC_IN6
PA7 ------> ADC_IN7
PC4 ------> ADC_IN14
PC5 ------> ADC_IN15
*/
GPIO_InitStruct.Pin =AD6_NOISE_Pin| AD0_V25_Pin|AD7_R_Pin;
GPIO_InitStruct.Mode =GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed=GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* GPIO_InitStruct.Pin = AD14_R_Pin|AD15_R_Pin;
GPIO_InitStruct.Mode =GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull =GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);*/
之后在while(1)前启动ad,调用如下
HAL_ADC_Start_DMA(&hadc, (uint32_t *)ADCConvertedDMABUF, 5);
之后测量各路的ad输入,正常应该是0V,可测量得到是0.4V左右,ad值为600左右。
离线
高手有空帮忙分析一下,第一次玩rc这个尾缀,有点闷逼了
离线
是不是供电不足
离线
不是供电不足,同样板子换st的103可以
离线
我用103,还是集成库,没问题,应该软件那里设置有问题吧
离线
已解决,跟串口的接收有冲突,f0潜在的bug。
离线
已解决,跟串口的接收有冲突,f0潜在的bug。
请问什么冲突哈
离线
ad 对应的io耐压是3.3V ,485的是5v,就这样给带坑里
离线