温度显示、设置及报警系统设计(我是菜鸟).1
硬件:
(1)2选用ST公司的stm32F446RE开发板;
(2)采用stm32F446RE内部温度传感器采集温度信号;
(3)PC上位机串口调试助手(AccessPort)实现温度的设置显示、及报警功能。
2.2 功能:
(1)温度显示格式:**.* ℃ ;
(2)采样(更新)频率:1Hz;
(3)温度报警事件通过上位机AccessPort任意;
(4)当温度显示“设定值时,AccessPort”(更新频率为1秒),并且LED灯发光(频率为10Hz);
(5),当用户按下时报警取消。
2.3报告要求:
(1)提交电子版及打印版1份(格式参考本字);
(2)运用DXP画出本stm32F446RE开发板的原理图及PCB(参考ST官方资料);
(3 )详细描述整体方案、程序流程以及各模块功能等。
2.4 设计要点:
(1)AD转换:获取温度
发送数值;(2)USART及接收:设置及采样;
(3)定时器定时器:LED灯亮点;
(4)中断服务:亮点广告。
谁能提提意见?
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_ADC1_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
int AD_Value;
float Vol_Value;
double Temperature;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1,10);
AD_Value = HAL_ADC_GetValue(&hadc1);
printf("ADC1_IN16 ADC value: %drn",AD_Value);
Vol_Value = AD_Value*(3.3/4096);
printf("ADC1_IN16 VOL value: %.2fVrn",Vol_Value);
Temperature = (1.43f - Vol_Value)/0.043f + 5;
if(flag == 0)
{
if(Temperature>15||Temperature<30)
{ //blink 1HZ
printf("Warning Warning Warning Warningrn");
HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);
HAL_Delay(100000);}
else
{printf("MCU Internal Temperature: %.2f¡ærn",Temperature);
printf("rn"); }
}
}
if(flag == 1)
{
GPIO_SetBits(LD2_GPIO_Port,LD2_Pin);
printf("MCU Internal Temperature: %.2f¡ærn",Temperature);
printf("rn");
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 72;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(flag == 1)
{
flag = 0;
}
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
代码错误如下:
*** Using Compiler 'V5.06 update 3 (build 300)', folder: 'D:BaiduNetdiskDownloadSTM32F4ARMARMCCBin'
Build target 'shiyan5'
compiling main.c...
.../Core /Src/main.c(121):警告:#111-D:语句无法访问
if(flag == 1)
…/Core/Src/main.c(123):警告:#223-D:函数“GPIO_SetBits” ” 隐式声明
GPIO_SetBits(LD2_GPIO_Port,LD2_Pin);
…/Core/Src/main.c: 2 个警告,0 个错误
链接…
程序大小:代码=8884 RO-data=508 RW-data=24 ZI-data=1160
FromELF:创建十六进制文件…
“shiyan5shiyan5.axf ” - 0 个错误,2 个警告。
已用构建时间:00:00:04
温度显示、设置及报警系统设计(我是菜鸟).1
硬件:
(1)2选用ST公司的stm32F446RE开发板;
(2)采用stm32F446RE内部温度传感器采集温度信号;
(3)PC上位机串口调试助手(AccessPort)实现温度的设置显示、及报警功能。
2.2 功能:
(1)温度显示格式:**.* ℃ ;
(2)采样(更新)频率:1Hz;
(3)温度报警事件通过上位机AccessPort任意;
(4)当温度显示“设定值时,AccessPort”(更新频率为1秒),并且LED灯发光(频率为10Hz);
(5),当用户按下时报警取消。
2.3报告要求:
(1)提交电子版及打印版1份(格式参考本字);
(2)运用DXP画出本stm32F446RE开发板的原理图及PCB(参考ST官方资料);
(3 )详细描述整体方案、程序流程以及各模块功能等。
2.4 设计要点:
(1)AD转换:获取温度
发送数值;(2)USART及接收:设置及采样;
(3)定时器定时器:LED灯亮点;
(4)中断服务:亮点广告。
谁能提提意见?
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_ADC1_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
int AD_Value;
float Vol_Value;
double Temperature;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1,10);
AD_Value = HAL_ADC_GetValue(&hadc1);
printf("ADC1_IN16 ADC value: %drn",AD_Value);
Vol_Value = AD_Value*(3.3/4096);
printf("ADC1_IN16 VOL value: %.2fVrn",Vol_Value);
Temperature = (1.43f - Vol_Value)/0.043f + 5;
if(flag == 0)
{
if(Temperature>15||Temperature<30)
{ //blink 1HZ
printf("Warning Warning Warning Warningrn");
HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);
HAL_Delay(100000);}
else
{printf("MCU Internal Temperature: %.2f¡ærn",Temperature);
printf("rn"); }
}
}
if(flag == 1)
{
GPIO_SetBits(LD2_GPIO_Port,LD2_Pin);
printf("MCU Internal Temperature: %.2f¡ærn",Temperature);
printf("rn");
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 72;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(flag == 1)
{
flag = 0;
}
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
代码错误如下:
*** Using Compiler 'V5.06 update 3 (build 300)', folder: 'D:BaiduNetdiskDownloadSTM32F4ARMARMCCBin'
Build target 'shiyan5'
compiling main.c...
.../Core /Src/main.c(121):警告:#111-D:语句无法访问
if(flag == 1)
…/Core/Src/main.c(123):警告:#223-D:函数“GPIO_SetBits” ” 隐式声明
GPIO_SetBits(LD2_GPIO_Port,LD2_Pin);
…/Core/Src/main.c: 2 个警告,0 个错误
链接…
程序大小:代码=8884 RO-data=508 RW-data=24 ZI-data=1160
FromELF:创建十六进制文件…
“shiyan5shiyan5.axf ” - 0 个错误,2 个警告。
已用构建时间:00:00:04
举报