本例程基于STM32F407VET6最小系统板,参考这位大佬的文章
过程不易,如有问题,本小小博主看到了会及时回复哩!
1、正弦波
2、三角波
3、方波
核心代码:
int main(void)
{
/* USER CODE BEGIN 1 *//* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_USART1_UART_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start(&htim3);
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc_buff, 200); //让ADC1去采集200个数,存放到adc_buff数组里
/* USER CODE END 2 *//* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE *//* USER CODE BEGIN 3 */
for (uint16_t i = 0; i < 200; i++)
{
printf("%d,%.3f\n",i,adc_buff[i] * 3.3 / 4095); //数据打印,查看结果 一定要有两个数据,且·用逗号隔开,VOFA才能输出对应波形
}}
/* USER CODE END 3 */
}