Intelligent fire remote monitoring system based on RS-485 communication protocol and Modbus

Topics requirements:

  • After power monitoring terminal LED1 to LED8 are all turned off, LED 9 flashes once every 2 seconds (on for 0.5 second and off for 1.5 seconds).
  • When measured flame collection end, monitoring the effect of the lamp LED1 terminal to LED4 water occurs.
  • After collection end flame disappears, the monitor terminal light water retention effect.
  • Pressing the key KEY1 monitoring end, water can stop lamp effect.

Using two control module M3, a flame sensor module, select a control module M3 as a monitoring terminal, the other control module M3 installed flame sensor module as a collection terminal.

 

1, the "Acquisition-side program 485 .hex" file is downloaded to the collection end, using "485 Node Configuration Tool .exe" Configure collection end address is 0x01, the sensor type is a flame sensor. The collection terminal and the monitor terminal communication connection through a communication port 485 (J5 Interface) top right.

2, STM32CubeMX use graphical configuration tool to generate KEIL development project to monitor the end to save the STM32CubeMX own projects and to generate engineering project directory in.

Use STM32CubeMX follows:

  •  (1) LED1-LED9 and GPIO configuration where KEY1, serial port
  • Setting (2) USART2 as: baud rate 115200bps, 8 data bits, 1 stop bit, no parity bit.
  •  (3) PC9 pin 485 controls communication chip duplexer (low received, sending a high level).
  •  (4) complete clock tree configuration: frequency 72M
  •  Operating parameters (5) Configuration Timer
  •    (6) configure the debug port

 

 

 

 

 

 

 

 

 

 

 

 

3, after the end of power monitoring, LED1 to LED8 are off-board, LED 9 flashes once every 2 seconds (on for 0.5 second and off for 1.5 seconds).

/* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
        HAL_GPIO_WritePin(LED9_GPIO_Port,LED9_Pin,GPIO_PIN_RESET);
      HAL_Delay(500);
      HAL_GPIO_WritePin(LED9_GPIO_Port,LED9_Pin,GPIO_PIN_SET);
      HAL_Delay(1500);
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */

4、监测端每隔2秒向采集端查询一次火情,当采集端出现火情时,监测端的LED1至LED4按指定流水灯方式显示。当采集端火情消失后,监测端的LED1至LED4应保持流水灯显示方式。具体流水灯显示方式为LED1亮起->LED2亮起->LED3亮起->LED4亮起->LED1至LED4全部熄灭->重复前述效果,各显示切换间隔为1秒。

监测端每隔2秒向采集端查询一次火情,

 

 SendCmd()

/* USER CODE BEGIN 0 */
void SendCmd(void)
{
    uint8_t cmd[8] = {0};
    cmd[0] = 0x01;
    cmd[1] = 0x04;
    cmd[2] = 0x00;
    cmd[3] = 0x02;
    cmd[4] = 0x00;
    cmd[5] = 0x01;
    cmd[6] = 0x90;
    cmd[7] = 0x0A;
    HAL_GPIO_WritePin(CONPIN_GPIO_Port,CONPIN_Pin,GPIO_PIN_SET);
    HAL_UART_Transmit(&huart2,cmd,8,0xffff);
    HAL_GPIO_WritePin(CONPIN_GPIO_Port,CONPIN_Pin,GPIO_PIN_RESET);
    HAL_UART_Receive_IT(&huart2,rxBuf,7);
}

/* USER CODE END 0 */
 /* USER CODE BEGIN 2 */
//定时器6,7使能
  if(HAL_TIM_Base_Start_IT(&htim6) != HAL_OK)
  {
      Error_Handler();
  }
  if(HAL_TIM_Base_Start_IT(&htim7) != HAL_OK)
  {
      Error_Handler();
  }

  /* USER CODE END 2 */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
    if(htim->Instance == TIM6)
    {
        if(flag_fire == 1)
        {
            ledState = ledState>>1;
            ledState |= 0x0080;
            if(ledState == 0x00f8)
                ledState = 0;
            HAL_GPIO_WritePin(GPIOE,0xffff,GPIO_PIN_SET);
            HAL_GPIO_WritePin(GPIOE,ledState,GPIO_PIN_RESET);
        }
        
    }
    
    if(htim->Instance == TIM7)
    {
        SendCmd();        
    }
}

判断火情

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
    if(huart->Instance == USART2)
    {
        if((rxBuf[0] == 0x01) && (rxBuf[1] == 0x04))
        {
            uint16_t temp = 0;
            temp = ((uint16_t)rxBuf[3])<<8;
            temp = temp | rxBuf[4];
            if(temp > 100)
            {
                flag_fire = 1;
            }
        }
    }
    
}

按键停止流水灯

/* USER CODE BEGIN 4 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
    if(GPIO_Pin & GPIO_PIN_13)
    {
        if(flag_fire == 1)
        {
            flag_fire = 0;
            ledState = 0;
            HAL_GPIO_WritePin(GPIOE,0xffff,GPIO_PIN_SET);
        }
    }
}

Guess you like

Origin www.cnblogs.com/jsit-dj-it/p/12112922.html