stm32cubemx设计图如下:
把驱动文件添加到新建的工程中去:
添加到group中去,在main函数进行调用,调用的时候别忘了引入驱动头文件。
main函数代码:
/**
* @brief The application entry point.
* @retval int
*/
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_USART1_UART_Init();
MX_ADC1_Init();
MX_I2C1_Init();
/* USER CODE BEGIN 2 */
if(AHT20_Init() != 0)
{
Humiture.alive = 0;
user_main_printf("AHT20 Initialization failed\r\n");
}
else
{
Humiture.alive = 1;
user_main_printf("AHT20 Initialization succeeded\r\n");
}
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
AHT20_Get_Value(&Humiture);
printf("现在的温度是 : %.2f; 现在的湿度是 : %.2f \r\n",Humiture.Temp, Humiture.RH);
HAL_Delay(1000);
}
/* USER CODE END 3 */
}
编译代码上传后的结果:
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/kukunet/article/details/135509988
|