96 lines
2.0 KiB
C
96 lines
2.0 KiB
C
|
/*
|
|||
|
* user_main.h
|
|||
|
*
|
|||
|
* Created on: Nov 11, 2024
|
|||
|
* Author: 10425
|
|||
|
*/
|
|||
|
|
|||
|
#include "user.h"
|
|||
|
|
|||
|
void user_main()
|
|||
|
{
|
|||
|
uint8_t parameters[2];
|
|||
|
//开始空闲中断
|
|||
|
__HAL_UART_ENABLE_IT(&huart1,UART_IT_IDLE);
|
|||
|
__HAL_UART_CLEAR_IT(&huart1,UART_CLEAR_IDLEF|UART_CLEAR_TCF);
|
|||
|
|
|||
|
__HAL_UART_ENABLE_IT(&huart3,UART_IT_IDLE);
|
|||
|
__HAL_UART_CLEAR_IT(&huart3,UART_CLEAR_IDLEF|UART_CLEAR_TCF);
|
|||
|
|
|||
|
bsp_InitTimer();
|
|||
|
AHT20_Init(&SENx,2000,0x38);
|
|||
|
AT24C16_Init();
|
|||
|
|
|||
|
HAL_UART_DMAStop(&huart1);//复位DMA //串口DMA接受
|
|||
|
HAL_UART_Receive_DMA(&huart1,(uint8_t *)RxBuff1,sizeof(RxBuff1));
|
|||
|
|
|||
|
HAL_UART_DMAStop(&huart3);//复位DMA //串口DMA接受
|
|||
|
HAL_UART_Receive_DMA(&huart3,(uint8_t *)RxBuff3,sizeof(RxBuff3));
|
|||
|
|
|||
|
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)RegularConvData_Tab, ADCBUFF_LEN); //开启ADC转换
|
|||
|
|
|||
|
//DE发射器使能,高电平有效,RE接收器使能,低电平有效
|
|||
|
HAL_GPIO_WritePin(TXEN_485_GPIO_Port, TXEN_485_Pin, GPIO_PIN_RESET);
|
|||
|
|
|||
|
//读取硬件参数
|
|||
|
dev_reg.version = 100;
|
|||
|
HAL_StatusTypeDef status;
|
|||
|
status=AT24C16_ReadBytes(0, parameters, sizeof(parameters));
|
|||
|
if(status == HAL_OK)
|
|||
|
{
|
|||
|
dev_reg.addr = parameters[0]<<8| parameters[1];
|
|||
|
if(dev_reg.addr == -1 || dev_reg.addr ==0 )
|
|||
|
{
|
|||
|
dev_reg.addr =1;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// HAL_Delay(2000);
|
|||
|
// send_UI(8);
|
|||
|
// HAL_Delay(200);
|
|||
|
|
|||
|
bsp_StartAutoTimer(0, 500);
|
|||
|
bsp_StartAutoTimer(1, 80);
|
|||
|
bsp_StartAutoTimer(2,MYI2C_Tick); //计算温湿度
|
|||
|
while(1)
|
|||
|
{
|
|||
|
if(bsp_CheckTimer(0))
|
|||
|
{
|
|||
|
HAL_IWDG_Refresh(&hiwdg);
|
|||
|
HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
|
|||
|
|
|||
|
}
|
|||
|
if(bsp_CheckTimer(1))
|
|||
|
{
|
|||
|
ADC_MAX();
|
|||
|
|
|||
|
}
|
|||
|
if(bsp_CheckTimer(2))
|
|||
|
{
|
|||
|
AHT20_Handle(&SENx);
|
|||
|
if(SENx.Step == SENSOR_COMPLETE)
|
|||
|
{
|
|||
|
dev_reg.humidness = (int16_t)(SENx.RH*100);
|
|||
|
dev_reg.tempe = (int16_t)(SENx.T*100);
|
|||
|
}
|
|||
|
}
|
|||
|
if(usart1_count >0)
|
|||
|
{
|
|||
|
Usart_Receive();
|
|||
|
usart1_count = 0;
|
|||
|
}
|
|||
|
if(usart3_count >0)
|
|||
|
{
|
|||
|
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET);
|
|||
|
Usart_Receive();
|
|||
|
usart3_count = 0;
|
|||
|
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|