| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- /**
- * @Author: 李建
- * @Date: 2025/8/21 10:45
- * Description: MODBUS 从站
- * Copyright: Copyright (©) 2025 永续绿建. All rights reserved.
- */
- #ifndef ROOM_WIRE_CONTROLLER_MODBUS_SLAVE_H
- #define ROOM_WIRE_CONTROLLER_MODBUS_SLAVE_H
- #include "main.h"
- #define MB_PORT_NUM 2 // Number of UART port used for Modbus connection
- #define MB_DEV_SPEED 9600 // The communication speed of the UART
- #define MB_GPIO_RX 2 // uart rx gpio port
- #define MB_GPIO_TX 1 // uart tx gpio port
- #define MB_REG_HOLDING_START_AREA0 (0)
- #define MB_REG_HOLD_CNT (30)
- #define SLAVE_POWER_REG_ADDRESS (0) // 电源
- #define SLAVE_WORK_MODE_REG_ADDRESS (1) // 工作模式
- #define SLAVE_FRESH_MODE_ADDRESS_REGISTER (2) // 新风模式寄存器
- #define SLAVE_FAN_LEVEL_REG_ADDRESS (4) // 风速档位
- #define SLAVE_TW_VALVE_STAT_ADDRESS (5) // 二通阀状态
- #define SLAVE_FAV_FIRST_VOL (0x15) // 风机一档电压
- #define SLAVE_FAN_SECOND_VOL (0x16) // 风机二档电压
- #define SLAVE_FAN_THIRD_VOL (0x17) // 风机三档电压
- #define SLAVE_SET_TEMP_REG_ADDRESS (0x0E) // 设置温度
- #define SLAVE_ENV_TEMP_REG_ADDRESS (0x1B) // 环境温度
- #define SLAVE_ENV_HUMIDITY_REG_ADDRESS (0x1C) // 环境湿度
- #define SLAVE_COMMUNICATION_STATUS_REG_ADDRESS (8) // 通讯状态
- void modbus_slave_init();
- uint16_t modbus_get_reg(uint16_t address);
- void modbus_set_reg(uint16_t address, uint16_t value);
- void change_slave_id(uint16_t id);
- #endif //ROOM_WIRE_CONTROLLER_MODBUS_SLAVE_H
|