Files
433_STM32/Core/Inc/modbus_rtu_master.h

144 lines
5.2 KiB
C
Raw Normal View History

/**
******************************************************************************
* @file modbus_rtu_master.h
* @brief Modbus RTU Master
* @note RS485 (UART3) Modbus RTU Noris AMS
* 41161 ( 1160)
* Bit4-7 (///)
*
* main.c 使
* 1. (Type 0x10): PROTO_TYPE_IO
* DI
* 2. (Type 0xAA): 30
*
* @version 1.1
******************************************************************************
*/
#ifndef __MODBUS_RTU_MASTER_H
#define __MODBUS_RTU_MASTER_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f1xx_hal.h"
/* ================================================================
* Modbus RTU
*
* ================================================================ */
/** 从站设备地址 (Noris AMS 默认地址 = 1) */
#define MODBUS_RTU_SLAVE_ADDR 1
/** 目标寄存器偏移地址 (1160 对应 Noris 协议中的寄存器 41161) */
#define MODBUS_RTU_TARGET_REG 1160
/** 单次读取的寄存器数量 (当前只读取 1 个报警寄存器) */
#define MODBUS_RTU_REG_QTY 1
/** 轮询间隔 (毫秒),每隔此时间发送一次 Read Holding Registers 请求 */
#define MODBUS_RTU_POLL_INTERVAL 1000
/** 响应超时 (毫秒),发送请求后等待从站响应的最长时间,超时则丢弃本次轮询 */
#define MODBUS_RTU_RESP_TIMEOUT 500
/** 帧内字符间隔超时 (毫秒),接收过程中两个相邻字节的最大间隔时间,
* */
#define MODBUS_RTU_INTER_CHAR_TIMEOUT 10
/** 发送回波屏蔽时间 (毫秒)UART3 发送后屏蔽自身回波的时间窗口,
* */
#define MODBUS_RTU_TX_ECHO_MARGIN 10
/* ================================================================
* Noris AMS
* 16
*
* 41161 :
* Bit4: (Fire)
* Bit5: (Door)
* Bit6: (Bilge)
* Bit7: (Gas)
*
* :
* Bit0 Bit4 ()
* Bit1 Bit5 ()
* Bit2 Bit6 ()
* Bit3 Bit7 ()
* ================================================================ */
/** 提取火灾综合报警 (寄存器 Bit4) */
#define NORIS_FIRE_ALARM(reg) (((reg) >> 4) & 0x01)
/** 提取水密门综合报警 (寄存器 Bit5) */
#define NORIS_DOOR_ALARM(reg) (((reg) >> 5) & 0x01)
/** 提取舱底水综合报警 (寄存器 Bit6) */
#define NORIS_BILGE_ALARM(reg) (((reg) >> 6) & 0x01)
/** 提取气体检测综合报警 (寄存器 Bit7) */
#define NORIS_GAS_ALARM(reg) (((reg) >> 7) & 0x01)
/* ================================================================
*
* ================================================================ */
/** Modbus RTU 接收缓冲区最大长度 (字节)
* 7 64 */
#define MODBUS_RTU_MAX_RX_BUF 64
/* ================================================================
*
* ================================================================ */
/**
* @brief Modbus RTU Master
* @note IDLE
*
* @retval
*/
void ModbusRTU_Master_Init(void);
/**
* @brief Modbus RTU Master
* @note :
* IDLE WAIT_POLL WAIT_RESPONSE PROCESS IDLE
*
* :
* - IDLE: (1000ms)
* - WAIT_POLL: Modbus RTU
* - WAIT_RESPONSE:
* - PROCESS:
*
* @retval
*/
void ModbusRTU_Master_Task(void);
/**
* @brief Modbus RTU
* @note UART3 (HAL_UART_RxCpltCallback)
* WAIT_RESPONSE
* @param byte: UART3
* @retval
*/
void ModbusRTU_FeedRxByte(uint8_t byte);
/**
* @brief Modbus RTU
* @note :
* Bit0:
* Bit1:
* Bit2:
* Bit3:
* @retval (uint8_t)
*/
uint8_t ModbusRTU_GetAlarmState(void);
#ifdef __cplusplus
}
#endif
#endif