初级会员

- 积分
- 104
- 金钱
- 104
- 注册时间
- 2016-9-24
- 在线时间
- 23 小时
|
1金钱
void MX_ADC_Init(void)
{
ADC_ChannelConfTypeDef sConfig;
/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc.Instance = ADC1;
hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC;
hadc.Init.Resolution = ADC_RESOLUTION12b;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.EOCSelection = EOC_SINGLE_CONV;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
hadc.Init.ContinuousConvMode = ENABLE;
hadc.Init.DiscontinuousConvMode = DISABLE;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.DMAContinuousRequests = ENABLE;
hadc.Init.Overrun = OVR_DATA_OVERWRITTEN;
HAL_ADC_Init(&hadc);
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_3;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
}
void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__DMA1_CLK_ENABLE();
/* DMA interrupt init */
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
}
void init(void)
{
HAL_TIM_Base_Start(&htim1);
HAL_TIM_Base_Start_IT(&htim6);
HAL_ADC_Start_DMA(&hadc,(uint32_t *)ADC_value,8);
}
uint32_t time;
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim==&htim6)
{
if(++time>=500)
{
time=0;
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);
printf("%d\r\n",ADC_value[0]);
printf("%d\r\n",ADC_value[1]);
printf("%d\r\n",ADC_value[2]);
printf("%d\r\n",ADC_value[3]);
printf("%d\r\n",ADC_value[4]);
printf("%d\r\n",ADC_value[5]);
printf("%d\r\n",ADC_value[6]);
printf("%d\r\n\r\n",ADC_value[7]);
}
}
}
void main_1(void)
{
}
|
|