/** @defgroup ADC_External_trigger_Source_Regular ADC External Trigger Source Regular
* @{
*//* Note: Parameter ADC_SOFTWARE_START is a software parameter used for *//* compatibility with other STM32 devices. */#defineADC_EXTERNALTRIGCONV_T1_CC10x00000000U#defineADC_EXTERNALTRIGCONV_T1_CC2((uint32_t)ADC_CR2_EXTSEL_0)#defineADC_EXTERNALTRIGCONV_T1_CC3((uint32_t)ADC_CR2_EXTSEL_1)#defineADC_EXTERNALTRIGCONV_T2_CC2((uint32_t)(ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))#defineADC_EXTERNALTRIGCONV_T2_CC3((uint32_t)ADC_CR2_EXTSEL_2)#defineADC_EXTERNALTRIGCONV_T2_CC4((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0))#defineADC_EXTERNALTRIGCONV_T2_TRGO((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1))#defineADC_EXTERNALTRIGCONV_T3_CC1((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))#defineADC_EXTERNALTRIGCONV_T3_TRGO((uint32_t)ADC_CR2_EXTSEL_3)#defineADC_EXTERNALTRIGCONV_T4_CC4((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_0))#defineADC_EXTERNALTRIGCONV_T5_CC1((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1))#defineADC_EXTERNALTRIGCONV_T5_CC2((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))#defineADC_EXTERNALTRIGCONV_T5_CC3((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2))#defineADC_EXTERNALTRIGCONV_T8_CC1((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0))#defineADC_EXTERNALTRIGCONV_T8_TRGO((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1))#defineADC_EXTERNALTRIGCONV_Ext_IT11((uint32_t)ADC_CR2_EXTSEL)#defineADC_SOFTWARE_START((uint32_t)ADC_CR2_EXTSEL +1U)
🌿定时器2配置:更新频率1s触发转换一次。
🌿开启ADC中断
🌿开启定时器中断
🌿中断优先级分组设置:定时器2中断 > ADC1中断
📙业务代码完善
🌿在main函数中开启定时器2和ADC1
intmain(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_ADC1_Init();MX_USART1_UART_Init();MX_TIM2_Init();/* USER CODE BEGIN 2 */printf("TIM Trg ADC change\r\n");//84000000/8400/10000=__HAL_TIM_CLEAR_FLAG(&htim2, TIM_FLAG_UPDATE);HAL_TIM_Base_Start_IT(&htim2);HAL_ADC_Start_IT(&hadc1);/* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while(1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 */}/* USER CODE END 3 */}
返回倒数第 k 个节点
实例要求
1、实现一种算法,找出单向链表中倒数第 k 个节点;2、返回该节点的值;
示例:输入: 1->2->3->4->5 和 k 2
输出: 4
说明:给定的 k 保证是有效的。实…