然后在main函数中编写测试程序:
int main(void)
{
/* USER CODE BEGIN 1 */
int16_t temperature;
int16_t humidity;
/* USER CODE END 1 */
HAL_Init();
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_I2C1_Init();
/* USER CODE BEGIN 2 */
printf("HTS221 Test...\r\n");
HTS221_Init();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HTS221_Get_Temperature(&temperature);
printf("temperature:%2.1f", temperature / 10.0);
HTS221_Get_Humidity(&humidity);
printf(" humidity:%2.1f\n", humidity / 10.0);
HAL_Delay(500);
}
/* USER CODE END 3 */
}
|