更新:
1、频率输出错误修复,CHx和CHxN频道使用的PWM启动和停止函数不同; 2、HART波形:RST始终为高,RTS和TX同步,但pc收不到串口数据;
This commit is contained in:
parent
365eef3122
commit
daf63a4503
|
@ -33,7 +33,8 @@
|
||||||
"algorithm": "c",
|
"algorithm": "c",
|
||||||
"app_screen_setting.h": "c",
|
"app_screen_setting.h": "c",
|
||||||
"key_functions.h": "c",
|
"key_functions.h": "c",
|
||||||
"sstream": "c"
|
"sstream": "c",
|
||||||
|
"modbus_485.h": "c"
|
||||||
},
|
},
|
||||||
"C_Cpp.errorSquiggles": "disabled",
|
"C_Cpp.errorSquiggles": "disabled",
|
||||||
"idf.pythonInstallPath": "F:\\Espressif\\tools\\idf-python\\3.11.2\\python.exe",
|
"idf.pythonInstallPath": "F:\\Espressif\\tools\\idf-python\\3.11.2\\python.exe",
|
||||||
|
|
|
@ -103,12 +103,12 @@ typedef struct
|
||||||
//ITEMS_2
|
//ITEMS_2
|
||||||
char log_time[60][16]; //输入&输出记录,时间戳
|
char log_time[60][16]; //输入&输出记录,时间戳
|
||||||
float32 input_log_value[60]; //输入记录,实际值
|
float32 input_log_value[60]; //输入记录,实际值
|
||||||
SIG_FUNCTIONS_TYPE input_log_unit[60]; //输入记录,单位
|
SIG_FUNCTIONS_TYPE input_log_unit[60]; //输入记录,单位
|
||||||
float32 output_log_value[60]; //输出记录,实际值
|
float32 output_log_value[60]; //输出记录,实际值
|
||||||
SIG_FUNCTIONS_TYPE output_log_unit[60];//输出记录,单位
|
SIG_FUNCTIONS_TYPE output_log_unit[60]; //输出记录,单位
|
||||||
uint8_t hart_enable;
|
uint8_t hart_enable; //HART透传使能
|
||||||
uint8_t bluetooth_enable;
|
uint8_t bluetooth_enable; //蓝牙透传使能
|
||||||
uint8_t modbus_enable;
|
uint8_t modbus_enable; //MODBUS使能
|
||||||
|
|
||||||
//ITEMS_3
|
//ITEMS_3
|
||||||
uint8_t item3_page0_lightflag; //照明状态标志,0熄灭,1开启
|
uint8_t item3_page0_lightflag; //照明状态标志,0熄灭,1开启
|
||||||
|
|
|
@ -2,26 +2,29 @@
|
||||||
#define __APPS_GATHER_H
|
#define __APPS_GATHER_H
|
||||||
/**********************************************Drivers**********************************************/
|
/**********************************************Drivers**********************************************/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "tm1650.h"
|
|
||||||
#include "mux_signal.h"
|
|
||||||
#include "JLX240-00301-BN.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "modbus.h"
|
#include "usart.h"
|
||||||
#include "ble.h"
|
|
||||||
#include "hart.h"
|
|
||||||
#include "rn7302.h"
|
|
||||||
#include "SIG24130.h"
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "ip5310_i2c.h"
|
|
||||||
#include "eeprom_spi.h"
|
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "tim.h"
|
#include "tim.h"
|
||||||
|
|
||||||
|
#include "ip5310_i2c.h"
|
||||||
|
#include "eeprom_spi.h"
|
||||||
|
#include "tm1650.h"
|
||||||
|
#include "mux_signal.h"
|
||||||
|
#include "JLX240-00301-BN.h"
|
||||||
|
#include "ble.h"
|
||||||
|
#include "hart.h"
|
||||||
|
#include "rn7302.h"
|
||||||
|
#include "SIG24130.h"
|
||||||
|
#include "modbus_485.h"
|
||||||
|
#include "modbus_rtu.h"
|
||||||
|
|
||||||
extern osThreadId task_lcdHandle;
|
extern osThreadId task_lcdHandle;
|
||||||
extern osThreadId task_menuHandle;
|
extern osThreadId task_menuHandle;
|
||||||
extern uint8_t screen_suspend_flag;
|
extern uint8_t screen_suspend_flag;
|
||||||
|
|
|
@ -28,8 +28,8 @@ void tab_data_init(void)
|
||||||
eeprom_item_data_init();
|
eeprom_item_data_init();
|
||||||
|
|
||||||
//ITEMS_0 选项卡0(注释项位于EERPOM读取)
|
//ITEMS_0 选项卡0(注释项位于EERPOM读取)
|
||||||
tabdata.item0_page0_vunit = VOLTAGE_V; //电压单位
|
tabdata.item0_page0_vunit = VOLTAGE_V; //电压单位默认为V
|
||||||
tabdata.item0_page1_TCtype = TC_K; //默认为K类型的热电偶
|
tabdata.item0_page1_TCtype = TC_K; //默认为K类型的热电偶
|
||||||
|
|
||||||
//ITEMS_1(部分内容位于EERPOM读取)
|
//ITEMS_1(部分内容位于EERPOM读取)
|
||||||
|
|
||||||
|
@ -43,12 +43,12 @@ void tab_data_init(void)
|
||||||
sprintf(tabdata.log_time[0], "00:00:00");
|
sprintf(tabdata.log_time[0], "00:00:00");
|
||||||
tabdata.input_log_unit[0] = m5data.input_mode_type;
|
tabdata.input_log_unit[0] = m5data.input_mode_type;
|
||||||
tabdata.output_log_unit[0] = m5data.output_mode_type;
|
tabdata.output_log_unit[0] = m5data.output_mode_type;
|
||||||
tabdata.hart_enable = 0;
|
tabdata.hart_enable = 0; //HART默认使能状态
|
||||||
tabdata.bluetooth_enable = 0;
|
tabdata.bluetooth_enable = 0; //HART默认使能状态
|
||||||
tabdata.modbus_enable = 0;
|
tabdata.modbus_enable = 0; //HART默认使能状态
|
||||||
|
|
||||||
//ITEMS_3(部分内容位于EERPOM读取)
|
//ITEMS_3(部分内容位于EERPOM读取)
|
||||||
tabdata.item3_page0_lightflag = 0; //照明状态标志,0熄灭,1开启
|
tabdata.item3_page0_lightflag = 0; //照明状态标志,0熄灭,1开启
|
||||||
LIGHT_OFF;
|
LIGHT_OFF;
|
||||||
tabdata.item3_page0_saveflag = 0;
|
tabdata.item3_page0_saveflag = 0;
|
||||||
tabdata.item3_page0_resetflag = 0;
|
tabdata.item3_page0_resetflag = 0;
|
||||||
|
|
|
@ -41,10 +41,13 @@ void hart_communicate(st_scom *scom)
|
||||||
if (scom->tx_flag == TRUE)
|
if (scom->tx_flag == TRUE)
|
||||||
{
|
{
|
||||||
scom->tx_flag = FALSE;
|
scom->tx_flag = FALSE;
|
||||||
|
|
||||||
HART_RTS(RTS_ON);
|
HART_RTS(RTS_ON);
|
||||||
vTaskDelay(5);
|
vTaskDelay(15);
|
||||||
|
|
||||||
memcpy(scom->tx_buff, hart_data_test, sizeof(hart_data_test));
|
memcpy(scom->tx_buff, hart_data_test, sizeof(hart_data_test));
|
||||||
hart_send(&huart1, scom->tx_buff);
|
hart_send(&huart1, scom->tx_buff);
|
||||||
|
|
||||||
HART_RTS(RTS_OFF);
|
HART_RTS(RTS_OFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
#ifndef __MODBUS_H
|
#ifndef __MODBUS_485_H
|
||||||
#define __MODBUS_H
|
#define __MODBUS_485_H
|
||||||
#include "stdint.h"
|
|
||||||
#include "gpio.h"
|
#include "apps_gather.h"
|
||||||
#include "usart.h"
|
|
||||||
|
|
||||||
void parse_scom_485(st_scom *scom);
|
void parse_scom_485(st_scom *scom);
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
#ifndef __MODBUS_RTU_H
|
||||||
|
#define __MODBUS_RTU_H
|
||||||
|
|
||||||
|
#include "apps_gather.h"
|
||||||
|
|
||||||
|
/*--------------------------------- 宏定义 -----------------------------------*/
|
||||||
|
//功能码
|
||||||
|
#define ReadCoilState 0x01 //读取线圈状态
|
||||||
|
#define ReadDisInputState 0x02 //读取输入状态
|
||||||
|
#define ReadHoldReg 0x03 //读取保持寄存器
|
||||||
|
#define ReadInputReg 0x04 //读取输入寄存器
|
||||||
|
#define WriteSingleCoil 0x05 //强制写单线圈输出状态
|
||||||
|
#define WriteSingleReg 0x06 //预设(写)单寄存器
|
||||||
|
#define WriteMultiCoil 0x0F //强制写多线圈输出状态
|
||||||
|
#define WriteMultiReg 0x10 //预设(写)多寄存器
|
||||||
|
|
||||||
|
#define COIL_ADD_MIN 0x00
|
||||||
|
#define COIL_ADD_MAX 0x64
|
||||||
|
#define MAX_COIL_NUM ((COIL_ADD_MAX) - (COIL_ADD_MIN) + 1)
|
||||||
|
|
||||||
|
#define DIS_ADD_MIN 0x00
|
||||||
|
#define DIS_ADD_MAX 0x64
|
||||||
|
#define MAX_DIS_NUM ((DIS_ADD_MAX) - (DIS_ADD_MIN) + 1)
|
||||||
|
|
||||||
|
#define INPUT_REG_ADD_MIN 0x00
|
||||||
|
#define INPUT_REG_ADD_MAX 0x64
|
||||||
|
#define MAX_INPUT_REG_NUM ((INPUT_REG_ADD_MAX) - (INPUT_REG_ADD_MIN) + 1)
|
||||||
|
|
||||||
|
#define HOLD_REG_ADD_MIN 0x00
|
||||||
|
#define HOLD_REG_ADD_MAX 0x64
|
||||||
|
#define MAX_HOLD_REG_NUM ((HOLD_REG_ADD_MAX) - (HOLD_REG_ADD_MIN) + 1)
|
||||||
|
|
||||||
|
#define BROADCAST_ADDRESS 0x00
|
||||||
|
#define LOCAL_ADDRESS 0x01
|
||||||
|
|
||||||
|
#define MAKEWORD(a,b) ((uint16_t)(((uint8_t)(a)) | ((uint16_t)((uint8_t)(b))) << 8))
|
||||||
|
|
||||||
|
#define MAX_SIZE 255
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
MB_EX_NONE = 0x00,
|
||||||
|
MB_EX_ILLEGAL_FUNCTION = 0x01,
|
||||||
|
MB_EX_ILLEGAL_DATA_ADDRESS = 0x02,
|
||||||
|
MB_EX_ILLEGAL_DATA_VALUE = 0x03,
|
||||||
|
MB_EX_SLAVE_DEVICE_FAILURE = 0x04,
|
||||||
|
MB_EX_ACKNOWLEDGE = 0x05,
|
||||||
|
MB_EX_SLAVE_BUSY = 0x06,
|
||||||
|
MB_EX_MEMORY_PARITY_ERROR = 0x08,
|
||||||
|
MB_EX_GATEWAY_PATH_FAILED = 0x0A,
|
||||||
|
MB_EX_GATEWAY_TGT_FAILED = 0x0B
|
||||||
|
} eMBException;
|
||||||
|
|
||||||
|
typedef union var_reg
|
||||||
|
{
|
||||||
|
uint16_t SamData [MAX_INPUT_REG_NUM]; // 采样数据
|
||||||
|
uint16_t InputReg[MAX_INPUT_REG_NUM]; // Reg 与 SamData
|
||||||
|
}Var_Reg;
|
||||||
|
|
||||||
|
|
||||||
|
extern uint8_t CoilState[(MAX_COIL_NUM + 7) / 8];
|
||||||
|
extern uint8_t DisState [(MAX_DIS_NUM + 7) / 8];
|
||||||
|
extern uint16_t InputReg[MAX_INPUT_REG_NUM];
|
||||||
|
extern uint16_t HoldReg[MAX_HOLD_REG_NUM];
|
||||||
|
extern Var_Reg SamVarReg;
|
||||||
|
|
||||||
|
//MODBUS_RTU
|
||||||
|
void modbus_analysis_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen);
|
||||||
|
void modbus_process_rtu(void);
|
||||||
|
void readcoilstate_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen);
|
||||||
|
void readdisinputstate_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen);
|
||||||
|
void readholdreg_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen);
|
||||||
|
void readinputreg_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen);
|
||||||
|
void writesinglereg_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen);
|
||||||
|
void writemultireg_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen);
|
||||||
|
void writesinglecoil_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen);
|
||||||
|
void writemulticoil_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen);
|
||||||
|
void modbus_errfunction_rtu(uint8_t uCmdCode, uint8_t uErrorCode);
|
||||||
|
|
||||||
|
//MODBUD
|
||||||
|
uint16_t ModbusCRC16(uint8_t *ptr, uint16_t len);
|
||||||
|
void GetOneCoilVal(uint16_t wCoilAddr, uint8_t *pCoilVal);
|
||||||
|
void GetOneDisInputVal(uint16_t wDisInputAddr, uint8_t *pDisInputVal);
|
||||||
|
uint16_t GetHoldRegData(uint16_t RegAdd);
|
||||||
|
uint16_t GetInputRegData(uint16_t RegAdd);
|
||||||
|
void WriteHoldRegData(uint16_t wRegAddr, uint16_t RegData);
|
||||||
|
void WriteOneCoilData(uint16_t wRegAddr, uint16_t RegData);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,4 @@
|
||||||
/*
|
#include "modbus_485.h"
|
||||||
* @Author: wujunchao wujunchao@wuxismart.com
|
|
||||||
* @Date: 2024-12-24 08:18:25
|
|
||||||
* @LastEditors: wujunchao wujunchao@wuxismart.com
|
|
||||||
* @LastEditTime: 2025-03-17 09:31:06
|
|
||||||
* @FilePath: \signal_generator\App\MODBUS\modbus.c
|
|
||||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "FreeRTOS.h"
|
|
||||||
#include "task.h"
|
|
||||||
#include "stdio.h"
|
|
||||||
#include "modbus.h"
|
|
||||||
#include "usart.h"
|
|
||||||
#include "apps_gather.h"
|
|
||||||
|
|
||||||
//static void scom_485_send(UART_HandleTypeDef *huart, char *str)
|
//static void scom_485_send(UART_HandleTypeDef *huart, char *str)
|
||||||
//{
|
//{
|
||||||
|
@ -72,7 +58,9 @@ void transparent_485(st_scom *scom)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TRANS_MODBUS:
|
case TRANS_MODBUS:
|
||||||
{}
|
{
|
||||||
|
modbus_process_rtu();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TRANS_NONE:
|
case TRANS_NONE:
|
|
@ -0,0 +1,754 @@
|
||||||
|
#include "modbus_rtu.h"
|
||||||
|
|
||||||
|
uint8_t CoilState[(MAX_COIL_NUM + 7) / 8] = {0x00,0x00,0x00,0x00,0x00}; //线圈寄存器
|
||||||
|
uint8_t DisState[(MAX_DIS_NUM + 7) / 8] = {0x00,0x00,0x00,0x00,0x00,0x00}; //离散量寄存器
|
||||||
|
uint16_t InputReg[MAX_INPUT_REG_NUM] = {0x0000,0x0000,0x0000,0x0000}; //输入寄存器
|
||||||
|
uint16_t HoldReg[MAX_HOLD_REG_NUM] = {0, 0,0,0x00C8}; //保持寄存器
|
||||||
|
|
||||||
|
Var_Reg SamVarReg;
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : Modbus_Analysis
|
||||||
|
功 能 : CRC校验
|
||||||
|
参 数 : ptr--校验数组指针 len--校验数据长度
|
||||||
|
返 回 值 : CRC校验码,双字节
|
||||||
|
*******************************************************************************/
|
||||||
|
void modbus_analysis_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen)
|
||||||
|
{
|
||||||
|
uint8_t uSlaveAdd, uCmdCode;
|
||||||
|
|
||||||
|
if((upRxdbuf == NULL) || (wRxdLen < 2)) return;
|
||||||
|
|
||||||
|
uSlaveAdd = upRxdbuf[0];
|
||||||
|
uCmdCode = upRxdbuf[1];
|
||||||
|
|
||||||
|
// 从机地址为本机地址或者是广播帧
|
||||||
|
if((uSlaveAdd == LOCAL_ADDRESS) || (uSlaveAdd == BROADCAST_ADDRESS))
|
||||||
|
{
|
||||||
|
switch(uCmdCode)
|
||||||
|
{
|
||||||
|
case ReadCoilState:
|
||||||
|
readcoilstate_rtu(upRxdbuf + 2, wRxdLen - 2); // 读线圈状态
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ReadDisInputState:
|
||||||
|
readdisinputstate_rtu(upRxdbuf + 2, wRxdLen - 2); // 读离散输入状态
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ReadHoldReg:
|
||||||
|
readholdreg_rtu(upRxdbuf + 2, wRxdLen - 2); // 读取保持寄存器
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ReadInputReg:
|
||||||
|
readinputreg_rtu(upRxdbuf + 2, wRxdLen - 2); // 读取输入寄存器
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WriteSingleReg:
|
||||||
|
writesinglereg_rtu(upRxdbuf + 2, wRxdLen - 2); // 写单个寄存器
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WriteMultiCoil:
|
||||||
|
writemulticoil_rtu(upRxdbuf + 2, wRxdLen - 2); // 写多个线圈
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WriteMultiReg:
|
||||||
|
writemultireg_rtu(upRxdbuf + 2, wRxdLen - 2); // 写多个寄存器
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WriteSingleCoil:
|
||||||
|
writesinglecoil_rtu(upRxdbuf + 2, wRxdLen - 2); // 写单个线圈
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
modbus_errfunction_rtu(upRxdbuf[1], 0x01); // 错误码处理
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void modbus_process_rtu(void)
|
||||||
|
{
|
||||||
|
uint8_t *pFrame;
|
||||||
|
uint16_t wFrameLen = 0;
|
||||||
|
uint16_t wFrameCRC, wCalCRC;
|
||||||
|
|
||||||
|
pFrame = scom2_rs485.rx_buff; // 接收数据起始地址
|
||||||
|
wFrameLen = scom2_rs485.rx_len; // 接收数据长度
|
||||||
|
|
||||||
|
if(wFrameLen < 2) return; // 数据长度不是有效值
|
||||||
|
|
||||||
|
// 获取接收数据帧中的校验和
|
||||||
|
wFrameCRC = MAKEWORD(pFrame[wFrameLen - 2], pFrame[wFrameLen - 1]);
|
||||||
|
// 计算接收到的数据的校验和
|
||||||
|
wCalCRC = ModbusCRC16(pFrame, wFrameLen - 2);
|
||||||
|
if(wFrameCRC != wCalCRC) return;
|
||||||
|
|
||||||
|
modbus_analysis_rtu(scom2_rs485.rx_buff, scom2_rs485.rx_len);// 协议处理
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : ReadCoilStateFUNC
|
||||||
|
功 能 : 功能码:0x01,读取线圈
|
||||||
|
参 数 : 无
|
||||||
|
返 回 值 : 无
|
||||||
|
*发送:[硬件地址][01][线圈起始地址高][线圈起始地址低][线圈数量高][线圈数量低][CRC低][CRC高]
|
||||||
|
*返回:[硬件地址][01][字节长度][线圈值][线圈值][线圈值][CRC低][CRC高]
|
||||||
|
*******************************************************************************/
|
||||||
|
void readcoilstate_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen)
|
||||||
|
{
|
||||||
|
uint16_t wCoilStartAddr,wCoilNum,wTotalCoilNum,CRC16Temp;
|
||||||
|
uint8_t i,k,uCommIndexNum = 0,uByteCount,uCoilVal,uErrorCode,uExit = 0;
|
||||||
|
uint8_t upTxdbuf[MAX_SIZE] = {0};
|
||||||
|
|
||||||
|
wCoilStartAddr = MAKEWORD(upRxdbuf[1], upRxdbuf[0]); //获取线圈起始地址
|
||||||
|
wCoilNum = MAKEWORD(upRxdbuf[3], upRxdbuf[2]); //获取线圈个数
|
||||||
|
|
||||||
|
if((wCoilNum >= 0x0001) || (wCoilNum <= MAX_COIL_NUM))
|
||||||
|
{
|
||||||
|
if(((wCoilStartAddr <= COIL_ADD_MAX)) &&
|
||||||
|
(wCoilNum + wCoilStartAddr <= COIL_ADD_MAX + 1))//(wCoilStartAddr >= COIL_ADD_MIN) &&
|
||||||
|
{
|
||||||
|
uByteCount = (wCoilNum + 7) / 8; //返回数据字节个数
|
||||||
|
|
||||||
|
upTxdbuf[uCommIndexNum ++] = LOCAL_ADDRESS;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = ReadCoilState;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = uByteCount;
|
||||||
|
|
||||||
|
wTotalCoilNum = 0;
|
||||||
|
for(k = 0; k < uByteCount; k++)
|
||||||
|
{
|
||||||
|
upTxdbuf[uCommIndexNum] = 0;
|
||||||
|
for(i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
GetOneCoilVal(wCoilStartAddr + wTotalCoilNum,&uCoilVal);
|
||||||
|
upTxdbuf[uCommIndexNum] |= uCoilVal << i;
|
||||||
|
|
||||||
|
wTotalCoilNum ++;
|
||||||
|
if(wTotalCoilNum >= wCoilNum)
|
||||||
|
{
|
||||||
|
uExit = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uCommIndexNum ++;
|
||||||
|
|
||||||
|
if(uExit == 1)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CRC16Temp = ModbusCRC16(upTxdbuf, uCommIndexNum);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp & 0xFF);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp >> 8);
|
||||||
|
|
||||||
|
// MODBUS_UART.tx_size = (uCommIndexNum <= MODBUS_UART.tx_buf_cnt ? uCommIndexNum : MODBUS_UART.tx_buf_cnt);
|
||||||
|
// memcpy(MODBUS_UART.tx_buf, upTxdbuf, MODBUS_UART.tx_size);
|
||||||
|
// uart_send(&MODBUS_HUART, MODBUS_UART.tx_buf, MODBUS_UART.tx_size);
|
||||||
|
scom2_rs485.tx_len = (uCommIndexNum <= MAX_SIZE)?(uCommIndexNum):(MAX_SIZE);
|
||||||
|
memcpy(scom2_rs485.tx_buff, upTxdbuf, scom2_rs485.tx_len);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_ADDRESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
modbus_errfunction_rtu(ReadCoilState, uErrorCode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : ReadDisInputStateFUNC
|
||||||
|
功 能 : 功能码:0x02,读取离散量
|
||||||
|
参 数 : 无
|
||||||
|
返 回 值 : 无
|
||||||
|
*发送:[硬件地址][02][离散量起始地址高][离散量起始地址低][离散量数量高][离散量数量低][CRC低][CRC高]
|
||||||
|
*返回:[硬件地址][02][字节长度][离散量值][离散量值][离散量值][CRC低][CRC高]
|
||||||
|
*******************************************************************************/
|
||||||
|
void readdisinputstate_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen)
|
||||||
|
{
|
||||||
|
uint16_t wDisStartAddr,wDisNum,wTotalDisNum,CRC16Temp;
|
||||||
|
uint8_t i,k,uCommIndexNum = 0,uByteCount,uDisVal,uErrorCode,uExit = 0;
|
||||||
|
uint8_t upTxdbuf[MAX_SIZE];
|
||||||
|
|
||||||
|
wDisStartAddr = MAKEWORD(upRxdbuf[1], upRxdbuf[0]); //获取离散量起始地址
|
||||||
|
wDisNum = MAKEWORD(upRxdbuf[3], upRxdbuf[2]); //获取离散量个数
|
||||||
|
|
||||||
|
if((wDisNum >= 0x0001) || (wDisNum <= MAX_DIS_NUM))
|
||||||
|
{
|
||||||
|
if(((wDisStartAddr <= DIS_ADD_MAX)) &&
|
||||||
|
(wDisNum + wDisStartAddr <= DIS_ADD_MAX + 1))//(wDisStartAddr >= DIS_ADD_MIN) &&
|
||||||
|
{
|
||||||
|
uByteCount = (wDisNum + 7) / 8; //返回数据字节个数
|
||||||
|
|
||||||
|
upTxdbuf[uCommIndexNum ++] = LOCAL_ADDRESS;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = ReadDisInputState;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = uByteCount;
|
||||||
|
|
||||||
|
wTotalDisNum = 0;
|
||||||
|
for(k = 0; k < uByteCount; k++)
|
||||||
|
{
|
||||||
|
upTxdbuf[uCommIndexNum] = 0;
|
||||||
|
for(i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
GetOneDisInputVal(wDisStartAddr + wTotalDisNum,&uDisVal);
|
||||||
|
upTxdbuf[uCommIndexNum] |= uDisVal << i;
|
||||||
|
|
||||||
|
wTotalDisNum ++;
|
||||||
|
if(wTotalDisNum >= wDisNum)
|
||||||
|
{
|
||||||
|
uExit = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uCommIndexNum ++;
|
||||||
|
|
||||||
|
if(uExit == 1)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CRC16Temp = ModbusCRC16(upTxdbuf, uCommIndexNum);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp & 0xFF);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp >> 8);
|
||||||
|
|
||||||
|
// MODBUS_UART.tx_size = (uCommIndexNum <= MODBUS_UART.tx_buf_cnt ? uCommIndexNum : MODBUS_UART.tx_buf_cnt);
|
||||||
|
// memcpy(MODBUS_UART.tx_buf, upTxdbuf, MODBUS_UART.tx_size);
|
||||||
|
// uart_send(&MODBUS_HUART, MODBUS_UART.tx_buf, MODBUS_UART.tx_size);
|
||||||
|
scom2_rs485.tx_len = (uCommIndexNum <= MAX_SIZE)?(uCommIndexNum):(MAX_SIZE);
|
||||||
|
memcpy(scom2_rs485.tx_buff, upTxdbuf, scom2_rs485.tx_len);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_ADDRESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
modbus_errfunction_rtu(ReadDisInputState, uErrorCode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : ReadHoldRegFUNC
|
||||||
|
功 能 : 功能码:0x03,读取保持寄存器
|
||||||
|
参 数 : 无
|
||||||
|
返 回 值 : 无
|
||||||
|
*发送:[硬件地址][03][起始地址高][起始地址低][总寄存器数高][总寄存器数低][CRC低][CRC高]
|
||||||
|
*返回:[硬件地址][03][字节数][寄存器0高][寄存器0低][寄存器1高][寄存器1低][寄存器n高][寄存器n低][CRC低][CRC高]
|
||||||
|
*******************************************************************************/
|
||||||
|
void readholdreg_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen)
|
||||||
|
{
|
||||||
|
uint16_t wRegStartAdd, wRegLen, i, wRegValue, CRC16Temp;
|
||||||
|
uint8_t uErrorCode, uCommIndexNum = 0;
|
||||||
|
uint8_t upTxdbuf[MAX_SIZE];
|
||||||
|
|
||||||
|
if(upRxdbuf == NULL) return;
|
||||||
|
|
||||||
|
wRegStartAdd = MAKEWORD(upRxdbuf[1], upRxdbuf[0]); //获取寄存器起始地址
|
||||||
|
wRegLen = MAKEWORD(upRxdbuf[3], upRxdbuf[2]); //获取读取寄存器长度
|
||||||
|
|
||||||
|
if((wRegLen >= 0x01) && (wRegLen <= MAX_HOLD_REG_NUM))
|
||||||
|
{
|
||||||
|
if(((wRegStartAdd <= HOLD_REG_ADD_MAX)) &&
|
||||||
|
(((wRegStartAdd + wRegLen) >= HOLD_REG_ADD_MIN) && ((wRegStartAdd + wRegLen) <= HOLD_REG_ADD_MAX + 1)))//(wRegStartAdd >= HOLD_REG_ADD_MIN) &&
|
||||||
|
{
|
||||||
|
upTxdbuf[uCommIndexNum ++] = LOCAL_ADDRESS;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = ReadHoldReg;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = wRegLen * 2;
|
||||||
|
|
||||||
|
for(i = 0; i < wRegLen; i++)
|
||||||
|
{
|
||||||
|
//获取16位数据并返回
|
||||||
|
wRegValue = GetHoldRegData(wRegStartAdd + i);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(wRegValue >> 8);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(wRegValue & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
CRC16Temp = ModbusCRC16(upTxdbuf, uCommIndexNum);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp & 0xFF); // crc16低字节在前
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp >> 8); // crc16高字节在后
|
||||||
|
|
||||||
|
// MODBUS_UART.tx_size = (uCommIndexNum <= MODBUS_UART.tx_buf_cnt ? uCommIndexNum : MODBUS_UART.tx_buf_cnt);
|
||||||
|
// memcpy(MODBUS_UART.tx_buf, upTxdbuf, MODBUS_UART.tx_size);
|
||||||
|
// uart_send(&MODBUS_HUART, MODBUS_UART.tx_buf, MODBUS_UART.tx_size);
|
||||||
|
scom2_rs485.tx_len = (uCommIndexNum <= MAX_SIZE)?(uCommIndexNum):(MAX_SIZE);
|
||||||
|
memcpy(scom2_rs485.tx_buff, upTxdbuf, scom2_rs485.tx_len);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_ADDRESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_VALUE;
|
||||||
|
}
|
||||||
|
modbus_errfunction_rtu(ReadHoldReg, uErrorCode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : ReadInputRegFUNC
|
||||||
|
功 能 : 功能码:0x04,读取输入寄存器
|
||||||
|
参 数 : 无
|
||||||
|
返 回 值 : 无
|
||||||
|
*发送:[硬件地址][04][起始地址高][起始地址低][总寄存器数高][总寄存器数低][ CRC低 ][ CRC高 ]
|
||||||
|
*返回:[硬件地址][04][ 字节数 ][寄存器0高 ][ 寄存器0低 ][ 寄存器1高 ][ 寄存器1低 ][ 寄存器n高 ][ 寄存器n低 ][ CRC低 ][ CRC高 ]
|
||||||
|
*******************************************************************************/
|
||||||
|
void readinputreg_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen)
|
||||||
|
{
|
||||||
|
uint16_t wRegStartAdd, wRegLen, i, wRegValue, CRC16Temp;
|
||||||
|
uint8_t uErrorCode, uCommIndexNum = 0;
|
||||||
|
uint8_t upTxdbuf[MAX_SIZE];
|
||||||
|
|
||||||
|
if(upRxdbuf == NULL) return;
|
||||||
|
|
||||||
|
wRegStartAdd = MAKEWORD(upRxdbuf[1], upRxdbuf[0]); //获取寄存器起始地址
|
||||||
|
wRegLen = MAKEWORD(upRxdbuf[3], upRxdbuf[2]); //获取读取寄存器长度
|
||||||
|
|
||||||
|
if((wRegLen >= 0x01) && (wRegLen <= MAX_INPUT_REG_NUM))
|
||||||
|
{
|
||||||
|
if(((wRegStartAdd <= INPUT_REG_ADD_MAX)) &&
|
||||||
|
((wRegStartAdd + wRegLen) <= INPUT_REG_ADD_MAX + 1))//(wRegStartAdd >= INPUT_REG_ADD_MIN) &&
|
||||||
|
{
|
||||||
|
upTxdbuf[uCommIndexNum ++] = LOCAL_ADDRESS;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = ReadInputReg;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = wRegLen * 2;
|
||||||
|
|
||||||
|
for(i = 0; i < wRegLen; i++)
|
||||||
|
{
|
||||||
|
//获取16位数据并返回
|
||||||
|
wRegValue = GetInputRegData(wRegStartAdd + i);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(wRegValue >> 8);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(wRegValue & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
CRC16Temp = ModbusCRC16(upTxdbuf, uCommIndexNum);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp & 0xFF); // crc16低字节在前
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp >> 8); // crc16高字节在后
|
||||||
|
|
||||||
|
// MODBUS_UART.tx_size = (uCommIndexNum <= MODBUS_UART.tx_buf_cnt ? uCommIndexNum : MODBUS_UART.tx_buf_cnt);
|
||||||
|
// memcpy(MODBUS_UART.tx_buf, upTxdbuf, MODBUS_UART.tx_size);
|
||||||
|
// uart_send(&MODBUS_HUART, MODBUS_UART.tx_buf, MODBUS_UART.tx_size);
|
||||||
|
scom2_rs485.tx_len = (uCommIndexNum <= MAX_SIZE)?(uCommIndexNum):(MAX_SIZE);
|
||||||
|
memcpy(scom2_rs485.tx_buff, upTxdbuf, scom2_rs485.tx_len);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_ADDRESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_VALUE;
|
||||||
|
}
|
||||||
|
modbus_errfunction_rtu(ReadInputReg, uErrorCode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : WriteSingleRegFUNC
|
||||||
|
功 能 : 功能码:0x06 预设(写)单寄存器
|
||||||
|
参 数 : 无
|
||||||
|
返 回 值 : 无
|
||||||
|
*发送:[硬件地址][06][寄存器地址高][寄存器地址低][寄存器值高][寄存器值低][CRC低][CRC高]
|
||||||
|
*返回:[硬件地址][06][寄存器地址高][寄存器地址低][寄存器值高][寄存器值低][CRC低][CRC高]
|
||||||
|
*******************************************************************************/
|
||||||
|
void writesinglereg_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen)
|
||||||
|
{
|
||||||
|
uint16_t wRegAddr, wRegValue, CRC16Temp;
|
||||||
|
uint8_t uCommIndexNum = 0, uErrorCode;
|
||||||
|
uint8_t upTxdbuf[MAX_SIZE];
|
||||||
|
|
||||||
|
if(upRxdbuf == NULL) return;
|
||||||
|
|
||||||
|
wRegAddr = MAKEWORD(upRxdbuf[1], upRxdbuf[0]); //获取寄存器地址
|
||||||
|
wRegValue = MAKEWORD(upRxdbuf[3], upRxdbuf[2]); //获取数据
|
||||||
|
|
||||||
|
if((wRegAddr <= HOLD_REG_ADD_MAX))//(wRegAddr >= HOLD_REG_ADD_MIN) &&
|
||||||
|
{
|
||||||
|
WriteHoldRegData(wRegAddr, wRegValue);
|
||||||
|
|
||||||
|
upTxdbuf[uCommIndexNum ++] = LOCAL_ADDRESS;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = WriteSingleReg;
|
||||||
|
memcpy(upTxdbuf + uCommIndexNum, upRxdbuf, 4);
|
||||||
|
uCommIndexNum += 4;
|
||||||
|
|
||||||
|
CRC16Temp = ModbusCRC16(upTxdbuf, uCommIndexNum);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp & 0xFF); // crc16低字节在前
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp >> 8); // crc16高字节在后
|
||||||
|
|
||||||
|
// MODBUS_UART.tx_size = (uCommIndexNum <= MODBUS_UART.tx_buf_cnt ? uCommIndexNum : MODBUS_UART.tx_buf_cnt);
|
||||||
|
// memcpy(MODBUS_UART.tx_buf, upTxdbuf, MODBUS_UART.tx_size);
|
||||||
|
// uart_send(&MODBUS_HUART, MODBUS_UART.tx_buf, MODBUS_UART.tx_size);
|
||||||
|
scom2_rs485.tx_len = (uCommIndexNum <= MAX_SIZE)?(uCommIndexNum):(MAX_SIZE);
|
||||||
|
memcpy(scom2_rs485.tx_buff, upTxdbuf, scom2_rs485.tx_len);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_ADDRESS;
|
||||||
|
}
|
||||||
|
modbus_errfunction_rtu(WriteSingleReg, uErrorCode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : WriteMultiRegFUNC
|
||||||
|
功 能 : 功能码:0x10 写多个保持寄存器
|
||||||
|
参 数 : 无
|
||||||
|
返 回 值 : 无
|
||||||
|
*******************************************************************************/
|
||||||
|
void writemultireg_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen)
|
||||||
|
{
|
||||||
|
uint16_t i, wRegStartAdd, wRegNum, CRC16Temp, uErrorCode, wRegValue;
|
||||||
|
uint8_t uCommIndexNum = 0, uByteNum;
|
||||||
|
uint8_t upTxdbuf[MAX_SIZE];
|
||||||
|
|
||||||
|
if(upRxdbuf == NULL) return;
|
||||||
|
|
||||||
|
wRegStartAdd = MAKEWORD(upRxdbuf[1], upRxdbuf[0]); //获取寄存器地址
|
||||||
|
wRegNum = MAKEWORD(upRxdbuf[3], upRxdbuf[2]); //获取寄存器数量
|
||||||
|
uByteNum = upRxdbuf[4]; //获取字节数
|
||||||
|
|
||||||
|
if((wRegNum >= 0x01) && (wRegNum <= MAX_HOLD_REG_NUM) && (uByteNum == wRegNum * 2))
|
||||||
|
{
|
||||||
|
if(((wRegStartAdd <= HOLD_REG_ADD_MAX) &&
|
||||||
|
(wRegStartAdd + wRegNum <= HOLD_REG_ADD_MAX + 1)))//(wRegStartAdd >= HOLD_REG_ADD_MIN) &&
|
||||||
|
{
|
||||||
|
for(i = 0; i < wRegNum; i++)
|
||||||
|
{
|
||||||
|
wRegValue = MAKEWORD(upRxdbuf[6 + i * 2], upRxdbuf[5 + i * 2]);
|
||||||
|
WriteHoldRegData(wRegStartAdd + i, wRegValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
upTxdbuf[uCommIndexNum ++] = LOCAL_ADDRESS;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = WriteMultiReg;
|
||||||
|
memcpy(upTxdbuf + uCommIndexNum, upRxdbuf, 4);
|
||||||
|
uCommIndexNum += 4;
|
||||||
|
|
||||||
|
CRC16Temp = ModbusCRC16(upTxdbuf, uCommIndexNum);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp & 0xFF);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp >> 8);
|
||||||
|
|
||||||
|
// MODBUS_UART.tx_size = (uCommIndexNum <= MODBUS_UART.tx_buf_cnt ? uCommIndexNum : MODBUS_UART.tx_buf_cnt);
|
||||||
|
// memcpy(MODBUS_UART.tx_buf, upTxdbuf, MODBUS_UART.tx_size);
|
||||||
|
// uart_send(&MODBUS_HUART, MODBUS_UART.tx_buf, MODBUS_UART.tx_size);
|
||||||
|
scom2_rs485.tx_len = (uCommIndexNum <= MAX_SIZE)?(uCommIndexNum):(MAX_SIZE);
|
||||||
|
memcpy(scom2_rs485.tx_buff, upTxdbuf, scom2_rs485.tx_len);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_ADDRESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_VALUE;
|
||||||
|
}
|
||||||
|
modbus_errfunction_rtu(WriteMultiReg, uErrorCode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : WriteSingleCoilFUNC
|
||||||
|
功 能 : 功能码:0x05 写单个线圈寄存器
|
||||||
|
参 数 : 无
|
||||||
|
返 回 值 : 无
|
||||||
|
*******************************************************************************/
|
||||||
|
void writesinglecoil_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen)
|
||||||
|
{
|
||||||
|
uint16_t wCoilAddr, wCoilValue, CRC16Temp;
|
||||||
|
uint8_t uCommIndexNum = 0, uErrorCode;
|
||||||
|
uint8_t upTxdbuf[MAX_SIZE];
|
||||||
|
|
||||||
|
wCoilAddr = MAKEWORD(upRxdbuf[1], upRxdbuf[0]); //获取线圈地址
|
||||||
|
wCoilValue = MAKEWORD(upRxdbuf[3], upRxdbuf[2]); //获取线圈数据
|
||||||
|
|
||||||
|
if((wCoilValue == 0x0000) || (wCoilValue == 0xFF00))
|
||||||
|
{
|
||||||
|
if((wCoilAddr <= COIL_ADD_MAX))//(wCoilAddr >= DIS_ADD_MIN ) &&
|
||||||
|
{
|
||||||
|
WriteOneCoilData(wCoilAddr, wCoilValue);
|
||||||
|
|
||||||
|
upTxdbuf[uCommIndexNum ++] = LOCAL_ADDRESS;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = WriteSingleCoil;
|
||||||
|
memcpy(upTxdbuf + uCommIndexNum, upRxdbuf, 4);
|
||||||
|
uCommIndexNum += 4;
|
||||||
|
|
||||||
|
CRC16Temp = ModbusCRC16(upTxdbuf, uCommIndexNum);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp & 0xFF);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp >> 8);
|
||||||
|
|
||||||
|
// MODBUS_UART.tx_size = (uCommIndexNum <= MODBUS_UART.tx_buf_cnt ? uCommIndexNum : MODBUS_UART.tx_buf_cnt);
|
||||||
|
// memcpy(MODBUS_UART.tx_buf, upTxdbuf, MODBUS_UART.tx_size);
|
||||||
|
// uart_send(&MODBUS_HUART, MODBUS_UART.tx_buf, MODBUS_UART.tx_size);
|
||||||
|
scom2_rs485.tx_len = (uCommIndexNum <= MAX_SIZE)?(uCommIndexNum):(MAX_SIZE);
|
||||||
|
memcpy(scom2_rs485.tx_buff, upTxdbuf, scom2_rs485.tx_len);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_ADDRESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_VALUE;
|
||||||
|
}
|
||||||
|
modbus_errfunction_rtu(WriteSingleCoil, uErrorCode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : WriteMultiCoilFUNC
|
||||||
|
功 能 : 功能码:0x0F,写多个线圈
|
||||||
|
参 数 : 无
|
||||||
|
返 回 值 : 无
|
||||||
|
*发送:[硬件地址][0F][起始地址高][起始地址低][线圈数量高][线圈数量低][字节数][线圈值][CRC低][CRC高]
|
||||||
|
*返回:[硬件地址][0F][起始地址高][起始地址低][线圈数量高][线圈数量低][CRC低][CRC高]
|
||||||
|
*******************************************************************************/
|
||||||
|
void writemulticoil_rtu(uint8_t * upRxdbuf, uint16_t wRxdLen)
|
||||||
|
{
|
||||||
|
uint16_t wCoilStartAddr,wCoilNum,wCoilVal,wTotalCoilNum,CRC16Temp;
|
||||||
|
uint8_t i,k,uCommIndexNum = 0,uByteNum,uByteVal,uExit = 0,uErrorCode;
|
||||||
|
uint8_t upTxdbuf[MAX_SIZE];
|
||||||
|
|
||||||
|
wCoilStartAddr = MAKEWORD(upRxdbuf[1], upRxdbuf[0]); //获取线圈地址
|
||||||
|
wCoilNum = MAKEWORD(upRxdbuf[3], upRxdbuf[2]); //获取线圈个数
|
||||||
|
uByteNum = upRxdbuf[4]; //获取字节数
|
||||||
|
|
||||||
|
if((wCoilNum >= 0x01) && (wCoilNum <= MAX_COIL_NUM) && (wCoilNum <= 8 * uByteNum))
|
||||||
|
{
|
||||||
|
if((wCoilStartAddr <= COIL_ADD_MAX) &&
|
||||||
|
(wCoilStartAddr + wCoilNum <= COIL_ADD_MAX + 1))//(wCoilStartAddr >= COIL_ADD_MIN) &&
|
||||||
|
{
|
||||||
|
wTotalCoilNum = 0;
|
||||||
|
for(k = 0; k < uByteNum; k++)
|
||||||
|
{
|
||||||
|
uByteVal = upRxdbuf[5 + k];
|
||||||
|
for(i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
if(uByteVal & (1 << i)) wCoilVal = 0xFF00;
|
||||||
|
else wCoilVal = 0x0000;
|
||||||
|
|
||||||
|
WriteOneCoilData(wCoilStartAddr + wTotalCoilNum, wCoilVal);
|
||||||
|
|
||||||
|
wTotalCoilNum ++;
|
||||||
|
if(wTotalCoilNum >= wCoilNum)
|
||||||
|
{
|
||||||
|
uExit = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(uExit == 1)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
upTxdbuf[uCommIndexNum ++] = LOCAL_ADDRESS;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = WriteMultiCoil;
|
||||||
|
memcpy(upTxdbuf + uCommIndexNum, upRxdbuf, 4);
|
||||||
|
uCommIndexNum += 4;
|
||||||
|
|
||||||
|
CRC16Temp = ModbusCRC16(upTxdbuf, uCommIndexNum);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp & 0xFF);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp >> 8);
|
||||||
|
|
||||||
|
// MODBUS_UART.tx_size = (uCommIndexNum <= MODBUS_UART.tx_buf_cnt ? uCommIndexNum : MODBUS_UART.tx_buf_cnt);
|
||||||
|
// memcpy(MODBUS_UART.tx_buf, upTxdbuf, MODBUS_UART.tx_size);
|
||||||
|
// uart_send(&MODBUS_HUART, MODBUS_UART.tx_buf, MODBUS_UART.tx_size);
|
||||||
|
scom2_rs485.tx_len = (uCommIndexNum <= MAX_SIZE)?(uCommIndexNum):(MAX_SIZE);
|
||||||
|
memcpy(scom2_rs485.tx_buff, upTxdbuf, scom2_rs485.tx_len);
|
||||||
|
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_ADDRESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uErrorCode = MB_EX_ILLEGAL_DATA_VALUE;
|
||||||
|
}
|
||||||
|
modbus_errfunction_rtu(WriteMultiCoil, uErrorCode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/********
|
||||||
|
***********************************************************************
|
||||||
|
函数名称 : MODBUS_ERRFunction
|
||||||
|
功 能: 错误回应指令
|
||||||
|
参 数: 无
|
||||||
|
返 回 值: 无
|
||||||
|
异常功能码 = 功能码+0x80
|
||||||
|
*******************************************************************************/
|
||||||
|
void modbus_errfunction_rtu(uint8_t uCmdCode, uint8_t uErrorCode)
|
||||||
|
{
|
||||||
|
uint8_t uCommIndexNum = 0;
|
||||||
|
uint16_t CRC16Temp = 0;
|
||||||
|
uint8_t upTxdbuf[MAX_SIZE];
|
||||||
|
|
||||||
|
upTxdbuf[uCommIndexNum ++] = LOCAL_ADDRESS;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = uCmdCode | 0x80;
|
||||||
|
upTxdbuf[uCommIndexNum ++] = uErrorCode;
|
||||||
|
|
||||||
|
CRC16Temp = ModbusCRC16(upTxdbuf, uCommIndexNum);
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp & 0xFF); //crc16低字节在前
|
||||||
|
upTxdbuf[uCommIndexNum ++] = (uint8_t)(CRC16Temp >> 8);
|
||||||
|
|
||||||
|
// MODBUS_UART.tx_size = (uCommIndexNum <= MODBUS_UART.tx_buf_cnt ? uCommIndexNum : MODBUS_UART.tx_buf_cnt);
|
||||||
|
// memcpy(MODBUS_UART.tx_buf, upTxdbuf, MODBUS_UART.tx_size);
|
||||||
|
// uart_send(&MODBUS_HUART, MODBUS_UART.tx_buf, MODBUS_UART.tx_size);
|
||||||
|
scom2_rs485.tx_len = (uCommIndexNum <= MAX_SIZE)?(uCommIndexNum):(MAX_SIZE);
|
||||||
|
memcpy(scom2_rs485.tx_buff, upTxdbuf, scom2_rs485.tx_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : ModbusCRC16
|
||||||
|
功 能 : CRC校验
|
||||||
|
参 数 : ptr--校验数组指针 len--校验数据长度
|
||||||
|
返 回 值 : CRC校验码,双字节
|
||||||
|
*******************************************************************************/
|
||||||
|
uint16_t ModbusCRC16(uint8_t *ptr, uint16_t len)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
uint16_t crc = ~0x00;
|
||||||
|
|
||||||
|
if((ptr == NULL) || (len == 0xFFFF)) return crc;
|
||||||
|
|
||||||
|
while(len--)
|
||||||
|
{
|
||||||
|
crc ^= *ptr++;
|
||||||
|
for(i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
if(crc & 0x01)
|
||||||
|
{
|
||||||
|
crc >>= 1;
|
||||||
|
crc ^= 0xA001;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
crc >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetOneCoilVal(uint16_t wCoilAddr, uint8_t *pCoilVal)
|
||||||
|
{
|
||||||
|
uint8_t uVal;
|
||||||
|
|
||||||
|
uVal = CoilState[(wCoilAddr - COIL_ADD_MIN) / 8 ];
|
||||||
|
if(uVal & ( 1 << ((wCoilAddr - COIL_ADD_MIN) % 8 )))
|
||||||
|
{
|
||||||
|
*pCoilVal = 0x01;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*pCoilVal = 0x00;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetOneDisInputVal(uint16_t wDisInputAddr, uint8_t *pDisInputVal)
|
||||||
|
{
|
||||||
|
uint8_t uVal;
|
||||||
|
|
||||||
|
uVal = DisState[(wDisInputAddr - DIS_ADD_MIN) / 8 ];
|
||||||
|
if(uVal & ( 1 << ((wDisInputAddr - DIS_ADD_MIN) % 8 )))
|
||||||
|
{
|
||||||
|
*pDisInputVal = 0x01;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*pDisInputVal = 0x00;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : GetHoldRegData
|
||||||
|
功 能 : 获取RegAdd的数据
|
||||||
|
参 数 : u16 RegAdd
|
||||||
|
返 回 值 : 两字节寄存器数据
|
||||||
|
*******************************************************************************/
|
||||||
|
uint16_t GetHoldRegData(uint16_t RegAdd)
|
||||||
|
{
|
||||||
|
int16_t wRegValue;
|
||||||
|
|
||||||
|
wRegValue = HoldReg[RegAdd - HOLD_REG_ADD_MIN];
|
||||||
|
|
||||||
|
return wRegValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : GetInputRegData
|
||||||
|
功 能 : 获取RegAdd的数据
|
||||||
|
参 数 : u16 RegAdd
|
||||||
|
返 回 值 : 两字节寄存器数据
|
||||||
|
*******************************************************************************/
|
||||||
|
uint16_t GetInputRegData(uint16_t RegAdd)
|
||||||
|
{
|
||||||
|
int16_t wRegValue;
|
||||||
|
|
||||||
|
wRegValue = InputReg[RegAdd - INPUT_REG_ADD_MIN];
|
||||||
|
|
||||||
|
return wRegValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : WriteHoldRegData
|
||||||
|
功 能 : 保存写入的保持寄存器数据
|
||||||
|
参 数 : u16 StartAdd
|
||||||
|
返 回 值 : 无
|
||||||
|
*******************************************************************************/
|
||||||
|
void WriteHoldRegData(uint16_t wRegAddr, uint16_t RegData)
|
||||||
|
{
|
||||||
|
HoldReg[wRegAddr - HOLD_REG_ADD_MIN] = RegData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
函数名称 : WriteOneCoilData
|
||||||
|
功 能 : 保存写入的线圈寄存器数据
|
||||||
|
参 数 : u16 StartAdd
|
||||||
|
返 回 值 : 无
|
||||||
|
*******************************************************************************/
|
||||||
|
void WriteOneCoilData(uint16_t wRegAddr, uint16_t RegData)
|
||||||
|
{
|
||||||
|
if(RegData == 0xFF00)
|
||||||
|
{
|
||||||
|
CoilState[(wRegAddr - COIL_ADD_MIN) / 8] |= 1 << ((wRegAddr - COIL_ADD_MIN) % 8);
|
||||||
|
}
|
||||||
|
else if(RegData == 0x0000)
|
||||||
|
{
|
||||||
|
CoilState[(wRegAddr - COIL_ADD_MIN) / 8] &= ~(1 << ((wRegAddr - COIL_ADD_MIN) % 8));
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,6 +25,7 @@
|
||||||
#include "dac8552.h"
|
#include "dac8552.h"
|
||||||
#include "ads1220.h"
|
#include "ads1220.h"
|
||||||
#include "dac7811.h"
|
#include "dac7811.h"
|
||||||
|
#include "apps_gather.h"
|
||||||
|
|
||||||
st_mux_signal mux_signal = {
|
st_mux_signal mux_signal = {
|
||||||
.channel = CHX_IN_MAX,
|
.channel = CHX_IN_MAX,
|
||||||
|
@ -144,9 +145,14 @@ void mux_signal_switch(st_mux_signal *mux_signal)
|
||||||
// ads1220_operation(CH2_OUT_CUR, &mux_signal->data_pv);
|
// ads1220_operation(CH2_OUT_CUR, &mux_signal->data_pv);
|
||||||
break;
|
break;
|
||||||
case CH3_OUT_FRE:
|
case CH3_OUT_FRE:
|
||||||
freq_operation(mux_signal->data_sv, pulse, TIM_CHANNEL_2);
|
{
|
||||||
fre_set = mux_signal->data_sv;
|
if(tabdata.hart_enable == 0)
|
||||||
fun_get_freq(&freq_signal, &mux_signal->data_pv);
|
{
|
||||||
|
freq_operation(mux_signal->data_sv, pulse, TIM_CHANNEL_2);
|
||||||
|
fre_set = mux_signal->data_sv;
|
||||||
|
fun_get_freq(&freq_signal, &mux_signal->data_pv);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CH4_OUT_RES:
|
case CH4_OUT_RES:
|
||||||
fun_dac7811_operate(&mux_signal->data_sv);
|
fun_dac7811_operate(&mux_signal->data_sv);
|
||||||
|
|
|
@ -111,6 +111,8 @@ void Error_Handler(void);
|
||||||
#define INPUT_A0_1_GPIO_Port GPIOE
|
#define INPUT_A0_1_GPIO_Port GPIOE
|
||||||
#define INPUT_A2_Pin GPIO_PIN_12
|
#define INPUT_A2_Pin GPIO_PIN_12
|
||||||
#define INPUT_A2_GPIO_Port GPIOE
|
#define INPUT_A2_GPIO_Port GPIOE
|
||||||
|
#define HART_4608_Pin GPIO_PIN_13
|
||||||
|
#define HART_4608_GPIO_Port GPIOE
|
||||||
#define INPUT_A1_Pin GPIO_PIN_14
|
#define INPUT_A1_Pin GPIO_PIN_14
|
||||||
#define INPUT_A1_GPIO_Port GPIOE
|
#define INPUT_A1_GPIO_Port GPIOE
|
||||||
#define INPUT_A0_Pin GPIO_PIN_15
|
#define INPUT_A0_Pin GPIO_PIN_15
|
||||||
|
|
|
@ -33,16 +33,20 @@ extern "C" {
|
||||||
#define freq_operation(FREQ, PULSE, CHAN) \
|
#define freq_operation(FREQ, PULSE, CHAN) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
|
HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_2); \
|
||||||
|
HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_3); \
|
||||||
if (FREQ <= 0 || FREQ >= 500000 || PULSE <= 0 || PULSE >= 100) \
|
if (FREQ <= 0 || FREQ >= 500000 || PULSE <= 0 || PULSE >= 100) \
|
||||||
{ \
|
{ \
|
||||||
HAL_TIMEx_PWMN_Stop(&htim1, CHAN); \
|
__HAL_TIM_SET_PRESCALER(&htim1, 1500-1); \
|
||||||
|
__HAL_TIM_SET_AUTORELOAD(&htim1, 55-1); \
|
||||||
|
__HAL_TIM_SET_COMPARE(&htim1, CHAN, 28-1); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
int fre_duty = 0; \
|
int fre_duty = 0; \
|
||||||
if(FREQ <= 50000) \
|
if(FREQ <= 650) \
|
||||||
{ \
|
{ \
|
||||||
__HAL_TIM_SET_PRESCALER(&htim1, 1600-1); \
|
__HAL_TIM_SET_PRESCALER(&htim1, 1500-1); \
|
||||||
fre_duty = ( (float32)FREQ_SYS / (float32)1600.0 / (float32)FREQ + (float32)0.5 ); \
|
fre_duty = ( (float32)FREQ_SYS / (float32)1500.0 / (float32)FREQ + (float32)0.5 ); \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
|
@ -51,9 +55,17 @@ extern "C" {
|
||||||
} \
|
} \
|
||||||
__HAL_TIM_SET_AUTORELOAD(&htim1, fre_duty -1); \
|
__HAL_TIM_SET_AUTORELOAD(&htim1, fre_duty -1); \
|
||||||
__HAL_TIM_SET_COMPARE(&htim1, CHAN, fre_duty *PULSE / 100 - 1); \
|
__HAL_TIM_SET_COMPARE(&htim1, CHAN, fre_duty *PULSE / 100 - 1); \
|
||||||
HAL_TIMEx_PWMN_Start(&htim1, CHAN); \
|
if( CHAN == TIM_CHANNEL_2) \
|
||||||
|
{ \
|
||||||
|
HAL_TIMEx_PWMN_Start(&htim1, CHAN); \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
HAL_TIM_PWM_Start(&htim1, CHAN); \
|
||||||
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
extern TIM_HandleTypeDef htim1;
|
extern TIM_HandleTypeDef htim1;
|
||||||
|
|
|
@ -204,7 +204,6 @@ void start_task_lcd(void const * argument)
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
uint8_t hart_test = 0;
|
uint8_t hart_test = 0;
|
||||||
uint8_t hart_cnt = 0;
|
|
||||||
/* USER CODE END Header_start_task_hart */
|
/* USER CODE END Header_start_task_hart */
|
||||||
void start_task_hart(void const * argument)
|
void start_task_hart(void const * argument)
|
||||||
{
|
{
|
||||||
|
@ -212,35 +211,27 @@ void start_task_hart(void const * argument)
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
//驱动验证,DEVICE <--- HART ---> SIG
|
if(tabdata.hart_enable == 1)
|
||||||
|
|
||||||
if(hart_test == 1)
|
|
||||||
{
|
{
|
||||||
hart_test = 2;
|
|
||||||
|
|
||||||
scom1_hart.tx_flag = TRUE;
|
|
||||||
|
|
||||||
if(fre_set != 460800)
|
if(fre_set != 460800)
|
||||||
{
|
{
|
||||||
freq_operation(460800, 50, TIM_CHANNEL_3);
|
freq_operation(460800, 50, TIM_CHANNEL_3);
|
||||||
fre_set = 460800;
|
fre_set = 460800;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(hart_test == 2)
|
//驱动验证,DEVICE <--- HART ---> SIG
|
||||||
{
|
hart_test++;
|
||||||
hart_cnt++;
|
if(hart_test > 100)
|
||||||
if(hart_cnt > 50)
|
|
||||||
{
|
{
|
||||||
hart_communicate(&scom1_hart);
|
|
||||||
hart_test = 0;
|
hart_test = 0;
|
||||||
hart_cnt = 0;
|
|
||||||
|
scom1_hart.tx_flag = TRUE;
|
||||||
|
hart_communicate(&scom1_hart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sig_trans = TRANS_HART;
|
||||||
|
// transparent_hart(&scom1_hart);
|
||||||
}
|
}
|
||||||
|
|
||||||
//transparent_hart(&scom1_hart);
|
|
||||||
|
|
||||||
tm1650_read_key(&hi2c1, &kp_flag, COMMAND_READ_KEY_DATA, &key);
|
|
||||||
|
|
||||||
osDelay(10);
|
osDelay(10);
|
||||||
}
|
}
|
||||||
|
@ -272,7 +263,11 @@ void start_task_ble(void const * argument)
|
||||||
ble_send(&huart6, scom6_ble.tx_buff);
|
ble_send(&huart6, scom6_ble.tx_buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
transparent_bluetooth(&scom6_ble);
|
if(tabdata.bluetooth_enable == 1)
|
||||||
|
{
|
||||||
|
sig_trans = TRANS_BLUETOOTH;
|
||||||
|
transparent_bluetooth(&scom6_ble);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
osDelay(BLE_TASK_PERIOD);
|
osDelay(BLE_TASK_PERIOD);
|
||||||
|
@ -292,7 +287,17 @@ void start_rs485(void const * argument)
|
||||||
/* USER CODE BEGIN start_rs485 */
|
/* USER CODE BEGIN start_rs485 */
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
if(tabdata.modbus_enable == 1)
|
||||||
|
{
|
||||||
|
sig_trans = TRANS_MODBUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !(tabdata.bluetooth_enable||tabdata.hart_enable||tabdata.modbus_enable) )
|
||||||
|
{
|
||||||
|
sig_trans = TRANS_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
transparent_485(&scom2_rs485);
|
transparent_485(&scom2_rs485);
|
||||||
|
|
||||||
osDelay(10);
|
osDelay(10);
|
||||||
|
@ -316,7 +321,12 @@ void start_mux_analog(void const * argument)
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
//按键扫描
|
||||||
|
tm1650_read_key(&hi2c1, &kp_flag, COMMAND_READ_KEY_DATA, &key);
|
||||||
|
|
||||||
|
//输出&输入通道切换
|
||||||
mux_signal_switch(&mux_signal);
|
mux_signal_switch(&mux_signal);
|
||||||
|
|
||||||
osDelay(50);
|
osDelay(50);
|
||||||
my_monitor_cnt++;
|
my_monitor_cnt++;
|
||||||
|
|
||||||
|
@ -353,7 +363,7 @@ void start_menu(void const * argument)
|
||||||
//挂起自身
|
//挂起自身
|
||||||
if( screen_suspend_flag == 1 ) vTaskSuspend(task_menuHandle);
|
if( screen_suspend_flag == 1 ) vTaskSuspend(task_menuHandle);
|
||||||
|
|
||||||
screen_run();
|
//screen_run();
|
||||||
|
|
||||||
osDelay(500);
|
osDelay(500);
|
||||||
system_sts.menu_stack_consume = uxTaskGetStackHighWaterMark(NULL);
|
system_sts.menu_stack_consume = uxTaskGetStackHighWaterMark(NULL);
|
||||||
|
|
|
@ -45,9 +45,9 @@ void MX_TIM1_Init(void)
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 1 */
|
/* USER CODE END TIM1_Init 1 */
|
||||||
htim1.Instance = TIM1;
|
htim1.Instance = TIM1;
|
||||||
htim1.Init.Prescaler = 90-1;
|
htim1.Init.Prescaler = 1500-1;
|
||||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
htim1.Init.Period = 922-1;
|
htim1.Init.Period = 55-1;
|
||||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
htim1.Init.RepetitionCounter = 0;
|
htim1.Init.RepetitionCounter = 0;
|
||||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
||||||
|
@ -71,7 +71,7 @@ void MX_TIM1_Init(void)
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||||
sConfigOC.Pulse = 461-1;
|
sConfigOC.Pulse = 28-1;
|
||||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||||
|
@ -81,7 +81,6 @@ void MX_TIM1_Init(void)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
|
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
|
@ -274,12 +273,12 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
|
GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
|
||||||
HAL_GPIO_Init(PWM_OUT_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(PWM_OUT_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_13;
|
GPIO_InitStruct.Pin = HART_4608_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
|
GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
|
||||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
HAL_GPIO_Init(HART_4608_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_MspPostInit 1 */
|
/* USER CODE BEGIN TIM1_MspPostInit 1 */
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -341,7 +341,7 @@
|
||||||
<MiscControls>--locale=english</MiscControls>
|
<MiscControls>--locale=english</MiscControls>
|
||||||
<Define>USE_HAL_DRIVER,STM32F407xx</Define>
|
<Define>USE_HAL_DRIVER,STM32F407xx</Define>
|
||||||
<Undefine></Undefine>
|
<Undefine></Undefine>
|
||||||
<IncludePath>../Core/Inc;../Drivers/STM32F4xx_HAL_Driver/Inc;../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy;../Middlewares/Third_Party/FreeRTOS/Source/include;../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS;../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F;../Drivers/CMSIS/Device/ST/STM32F4xx/Include;../Drivers/CMSIS/Include;../App/LCD;../App/MODBUS;../Utils/inc;../App/BLE;../App/MUX_SIGNAL;../App/DAC8552;../App/HART;../App/RN7302;../App/ADS1220;../App/TM1650;../App/DAC7811;../App/SIG24130;../LVGL;../LVGL/src;../LVGL/examples/porting;../LVGL/myGUI/generated;../LVGL/myGUI/custom;../LVGL/myGUI/generated/guider_fonts;../LVGL/myGUI/generated/guider_customer_fonts;../App/APP_WU/Src;../App/APP_WU/Inc;../LVGL/demos/benchmark;../LVGL/demos</IncludePath>
|
<IncludePath>../Core/Inc;../Drivers/STM32F4xx_HAL_Driver/Inc;../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy;../Middlewares/Third_Party/FreeRTOS/Source/include;../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS;../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F;../Drivers/CMSIS/Device/ST/STM32F4xx/Include;../Drivers/CMSIS/Include;../App/LCD;../Utils/inc;../App/BLE;../App/MUX_SIGNAL;../App/DAC8552;../App/HART;../App/RN7302;../App/ADS1220;../App/TM1650;../App/DAC7811;../App/SIG24130;../LVGL;../LVGL/src;../LVGL/examples/porting;../LVGL/myGUI/generated;../LVGL/myGUI/custom;../LVGL/myGUI/generated/guider_fonts;../LVGL/myGUI/generated/guider_customer_fonts;../App/APP_WU/Src;../App/APP_WU/Inc;../LVGL/demos/benchmark;../LVGL/demos;../App/MODBUS/Src;../App/MODBUS/Inc</IncludePath>
|
||||||
</VariousControls>
|
</VariousControls>
|
||||||
</Cads>
|
</Cads>
|
||||||
<Aads>
|
<Aads>
|
||||||
|
@ -751,9 +751,14 @@
|
||||||
<GroupName>Application/User/App/MODBUS</GroupName>
|
<GroupName>Application/User/App/MODBUS</GroupName>
|
||||||
<Files>
|
<Files>
|
||||||
<File>
|
<File>
|
||||||
<FileName>modbus.c</FileName>
|
<FileName>modbus_485.c</FileName>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<FilePath>..\App\MODBUS\modbus.c</FilePath>
|
<FilePath>..\App\MODBUS\Src\modbus_485.c</FilePath>
|
||||||
|
</File>
|
||||||
|
<File>
|
||||||
|
<FileName>modbus_rtu.c</FileName>
|
||||||
|
<FileType>1</FileType>
|
||||||
|
<FilePath>..\App\MODBUS\Src\modbus_rtu.c</FilePath>
|
||||||
</File>
|
</File>
|
||||||
</Files>
|
</Files>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -454,6 +454,9 @@ PE12.GPIOParameters=GPIO_Label
|
||||||
PE12.GPIO_Label=INPUT_A2
|
PE12.GPIO_Label=INPUT_A2
|
||||||
PE12.Locked=true
|
PE12.Locked=true
|
||||||
PE12.Signal=GPIO_Output
|
PE12.Signal=GPIO_Output
|
||||||
|
PE13.GPIOParameters=GPIO_PuPd,GPIO_Label
|
||||||
|
PE13.GPIO_Label=HART_4608
|
||||||
|
PE13.GPIO_PuPd=GPIO_PULLUP
|
||||||
PE13.Locked=true
|
PE13.Locked=true
|
||||||
PE13.Signal=S_TIM1_CH3
|
PE13.Signal=S_TIM1_CH3
|
||||||
PE14.GPIOParameters=PinState,GPIO_Label
|
PE14.GPIOParameters=PinState,GPIO_Label
|
||||||
|
@ -594,14 +597,16 @@ SPI3.VirtualType=VM_MASTER
|
||||||
TIM1.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
|
TIM1.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
|
||||||
TIM1.Channel-PWM\ Generation2\ CH2N=TIM_CHANNEL_2
|
TIM1.Channel-PWM\ Generation2\ CH2N=TIM_CHANNEL_2
|
||||||
TIM1.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3
|
TIM1.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3
|
||||||
TIM1.IPParameters=Prescaler,AutoReloadPreload,Period,OC2Preload_PWM,Channel-PWM Generation2 CH2N,Pulse-PWM Generation2 CH2N,OCFastMode_PWM-PWM Generation2 CH2N,OCMode_PWM-PWM Generation2 CH2N,Channel-PWM Generation3 CH3,Pulse-PWM Generation3 CH3
|
TIM1.IPParameters=Prescaler,AutoReloadPreload,Period,OC2Preload_PWM,Channel-PWM Generation2 CH2N,Pulse-PWM Generation2 CH2N,OCFastMode_PWM-PWM Generation2 CH2N,OCMode_PWM-PWM Generation2 CH2N,Channel-PWM Generation3 CH3,Pulse-PWM Generation3 CH3,OCFastMode_PWM-PWM Generation3 CH3,OCMode_PWM-PWM Generation3 CH3
|
||||||
TIM1.OC2Preload_PWM=ENABLE
|
TIM1.OC2Preload_PWM=ENABLE
|
||||||
TIM1.OCFastMode_PWM-PWM\ Generation2\ CH2N=TIM_OCFAST_ENABLE
|
TIM1.OCFastMode_PWM-PWM\ Generation2\ CH2N=TIM_OCFAST_ENABLE
|
||||||
|
TIM1.OCFastMode_PWM-PWM\ Generation3\ CH3=TIM_OCFAST_ENABLE
|
||||||
TIM1.OCMode_PWM-PWM\ Generation2\ CH2N=TIM_OCMODE_PWM1
|
TIM1.OCMode_PWM-PWM\ Generation2\ CH2N=TIM_OCMODE_PWM1
|
||||||
TIM1.Period=922-1
|
TIM1.OCMode_PWM-PWM\ Generation3\ CH3=TIM_OCMODE_PWM1
|
||||||
TIM1.Prescaler=90-1
|
TIM1.Period=55-1
|
||||||
TIM1.Pulse-PWM\ Generation2\ CH2N=461-1
|
TIM1.Prescaler=1500-1
|
||||||
TIM1.Pulse-PWM\ Generation3\ CH3=461-1
|
TIM1.Pulse-PWM\ Generation2\ CH2N=28-1
|
||||||
|
TIM1.Pulse-PWM\ Generation3\ CH3=28-1
|
||||||
TIM3.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
|
TIM3.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
|
||||||
TIM3.Channel-Input_Capture4_from_TI4=TIM_CHANNEL_4
|
TIM3.Channel-Input_Capture4_from_TI4=TIM_CHANNEL_4
|
||||||
TIM3.IPParameters=Channel-Input_Capture4_from_TI4,Prescaler,Period,AutoReloadPreload
|
TIM3.IPParameters=Channel-Input_Capture4_from_TI4,Prescaler,Period,AutoReloadPreload
|
||||||
|
|
Loading…
Reference in New Issue