modbus_slave.h 1.5 KB

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