實驗原理:
STM32內部整合12位DAC,可以配置成12位或8位,DAC具有兩個獨立轉換通道,
在雙DAC模式下,DA轉換可被配置成獨立模式或工作模式,iCore1S中DAC參考電壓為
2.5V。本實驗輸出2.0V電壓
核心程式碼:
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_DAC_Init(); /* USER CODE BEGIN 2 */ HAL_DAC_Start(&hdac, DAC_CHANNEL_1); dac.set_voltage(2.0); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ LED_RED_ON; LED_GREEN_OFF; LED_BLUE_OFF; HAL_Delay(1000); LED_RED_OFF; LED_GREEN_ON; LED_BLUE_OFF; HAL_Delay(1000); LED_RED_OFF; LED_GREEN_OFF; LED_BLUE_ON; HAL_Delay(1000); } /* USER CODE END 3 */ }
原始碼下載連結:
連結:http://pan.baidu.com/s/1i5b0kRV 密碼:p2h5