1:首先使用stm32cube 配置ADC的硬件配置
uint8_t tx_Value[2000];
struct ADC_Sample
{
int ADC_count;
uint32_t ADC1_Sample_data;
uint32_t SDADC_Sample_data[];
} ADC;
MX_ADC1_Init();
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
// CDC_Transmit_FS((uint8_t *)"Hello world !\r\n", sizeof("Hello world !\r\n"));
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 50);
if(HAL_IS_BIT_SET(HAL_ADC_GetState(&hadc1), HAL_ADC_STATE_REG_EOC))
{
ADC.ADC1_Sample_data = HAL_ADC_GetValue(&hadc1);
tx_Value[3]= ADC.ADC1_Sample_data & 0x00FF;
tx_Value[2]= (ADC.ADC1_Sample_data & 0xFF00)>>8 ;
}
tx_Value[0]=0X01;
tx_Value[1]=0XEF;
CDC_Transmit_FS(tx_Value,4);
HAL_Delay(500);
}