2.3.2 配置工程文件名、路径、ToolChain/IDE——>GENERATE CODE ,完成之后打开项目
main.c#include "main.h"
#include "adc.h"
#include "dma.h"
#include "usart.h"
#include "gpio.h"
#include "stdio.h"
uint32_t ADC_1 = 0, ADC_2 = 0;
uint32_t ADC_Value[100];
uint8_t i;
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_USART2_UART_Init();
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&ADC_Value, 100);//100数据量
printf("ADC Sampling start\r\n");
while (1)
{
HAL_Delay(500);//这里不加延时,采集输出值第一次为0
for(i=0; i<100;)
{
ADC_1 = ADC_Value[i++];
ADC_2 = ADC_Value[i++];
}
printf("double channel ADC test\r\n");
printf("ADC_1 = %1.4f\r\n", ADC_1*3.3f/4096);
printf("ADC_2 = %1.4f\r\n", ADC_2*3.3f/4096);
}
}
|