Pinout配置
时钟配置
SDADC1设备配置
DMA配置
中断配置
生成代码
修改main.c
-
添加保存SDADC转换结果数组
/* USER CODE BEGIN PV */
/* Private variables---------------------------------------------------------*/
TIMER_TypeDef tmrLed;
__IO int16_t InjectedConvData_SDADC1[5] = {0, 0, 0, 0, 0};
__IO uint32_t InjChannel = 0;
/* USER CODE END PV */
SDADC1校准
/* USER CODE BEGIN 2 */
/* Start Calibration in polling mode */
if(HAL_SDADC_CalibrationStart(&hsdadc1, SDADC_CALIBRATION_SEQ_1) != HAL_OK)
{
/* An error occurs duringthe starting phase of the calibration */
_Error_Handler(__FILE__,__LINE__);
}
/* Pool for the end ofcalibration */
if(HAL_SDADC_PollForCalibEvent(&hsdadc1, HAL_MAX_DELAY) != HAL_OK)
{
/* An error occurs whilewaiting for the end of the calibration */
_Error_Handler(__FILE__,__LINE__);
}
启动SDADC1
/* Start injected conversionin interrupt mode */
if(HAL_SDADC_InjectedStart_DMA(&hsdadc1, (uint32_t*)InjectedConvData_SDADC1,4) != HAL_OK)
{
/* An error occurs duringthe configuration of the injected conversion in interrupt mode */
_Error_Handler(__FILE__,__LINE__);
}
/* USER CODE END 2 */
完成代码,可以在调试窗口中观察InjectedConvData_SDADC1[]变量。
Single Ended Zero Reference mode下数据转换公式
(InjectedConvData_SDADC1[x]+ 32768) * SDADCVREF / 65535