diff --git a/Core/Dallas/dallas_tools.c b/Core/Dallas/dallas_tools.c
index 82f385d..f820d8d 100644
--- a/Core/Dallas/dallas_tools.c
+++ b/Core/Dallas/dallas_tools.c
@@ -286,12 +286,13 @@ HAL_StatusTypeDef Dallas_SensorDeInit(DALLAS_SensorHandleTypeDef *sensor)
{
if(sensor == NULL)
return HAL_ERROR;
-
- DALLAS_InitStructTypeDef initbuff = sensor->Init;
-
- memset(sensor, 0, sizeof(DALLAS_SensorHandleTypeDef));
-
- sensor->Init = initbuff;
+
+ memset(&sensor->f, 0, sizeof(sensor->f));
+ sensor->isConnected = 0;
+ sensor->isInitialized = 0;
+ sensor->isLost = 0;
+ sensor->temperature = 0;
+ sensor->sensROM = 0;
return HAL_OK;
}
diff --git a/Core/Dallas/ds18b20_driver.c b/Core/Dallas/ds18b20_driver.c
index d72ee1a..5e1f250 100644
--- a/Core/Dallas/ds18b20_driver.c
+++ b/Core/Dallas/ds18b20_driver.c
@@ -7,7 +7,7 @@
*/
#include "ds18b20_driver.h"
-DS18B20_Drv_t DS;
+DS18B20_Drv_t *DS;
OneWire_t OW;
/**
@@ -593,6 +593,12 @@ HAL_StatusTypeDef DS18B20_Search(DS18B20_Drv_t *DS, OneWire_t *OW)
OW->RomCnt++;
}
+ for(int i = OW->RomCnt; i < DS18B20_DEVICE_AMOUNT; i++)
+ {
+ for(int j = 0; j < 8; j++)
+ DS->DevAddr[i][j] = 0;
+ }
+
if(OW->RomCnt > 0)
return HAL_OK;
diff --git a/Core/Dallas/ds18b20_driver.h b/Core/Dallas/ds18b20_driver.h
index baf22f6..b5cf8d8 100644
--- a/Core/Dallas/ds18b20_driver.h
+++ b/Core/Dallas/ds18b20_driver.h
@@ -78,7 +78,7 @@ typedef struct
{
uint8_t DevAddr[DS18B20_DEVICE_AMOUNT][8];
} DS18B20_Drv_t;
-extern DS18B20_Drv_t DS;
+extern DS18B20_Drv_t *DS;;
extern OneWire_t OW;
/* External Function ---------------------------------------------------------*/
diff --git a/Core/Modbus/interface_config.h b/Core/Modbus/interface_config.h
index 456b4dd..c877134 100644
--- a/Core/Modbus/interface_config.h
+++ b/Core/Modbus/interface_config.h
@@ -21,7 +21,7 @@
#define MODBUS_VENDOR_NAME "NIO-12"
#define MODBUS_PRODUCT_CODE "12345"
#define MODBUS_REVISION "Ver. 1.0"
-#define MODBUS_VENDOR_URL "https://git.arktika.cyou/set506/DS18B20_Library/src/branch/py32f002b_dallas"
+#define MODBUS_VENDOR_URL "https://git.arktika.cyou/set506/DS18B20_Library/"
#define MODBUS_PRODUCT_NAME "Dallas Driver"
#define MODBUS_MODEL_NAME "PY32F002B"
#define MODBUS_USER_APPLICATION_NAME "PY32Dallas"
diff --git a/Core/Modbus/modbus.c b/Core/Modbus/modbus.c
index 5b29082..3d9f8a7 100644
--- a/Core/Modbus/modbus.c
+++ b/Core/Modbus/modbus.c
@@ -291,6 +291,11 @@ MB_ExceptionTypeDef MB_DefineRegistersAddress(uint16_t **pRegs, uint16_t Addr, u
extern void PYModule_IncrementScanSensor(void);
PYModule_IncrementScanSensor();
}
+ // Все найденные ROM на линии
+ else if(MB_Check_Address_For_Arr(Addr, Qnt, R_ALL_ROMS_ADDR, R_ALL_ROMS_QNT) == NO_ERRORS)
+ {
+ *pRegs = MB_Set_Register_Ptr(&MB_DATA.InRegs, Addr); // начало регистров хранения/входных
+ }
// if address doesnt match any array - return illegal data address response
else
{
diff --git a/Core/Modbus/modbus_data.h b/Core/Modbus/modbus_data.h
index 588cbab..102cc51 100644
--- a/Core/Modbus/modbus_data.h
+++ b/Core/Modbus/modbus_data.h
@@ -54,6 +54,8 @@ typedef struct //MB_DataInRegsTypeDef
{
uint16_t SensTemperature[DS18B20_DEVICE_AMOUNT];
MB_SensorParamsTypeDef Response;
+ uint16_t reserved;
+ uint16_t AllROMs[DS18B20_DEVICE_AMOUNT][4];
}MB_DataInRegsTypeDef;
@@ -69,8 +71,10 @@ typedef struct //MB_DataInRegsTypeDef
// DEFINES FOR INPUT REGISTERS ARRAYS
#define R_TEMPERATURE_ADDR (0)
#define R_TEMPERATURE_QNT (DS18B20_DEVICE_AMOUNT)
-#define R_SENS_PARAMS_ADDR (DS18B20_DEVICE_AMOUNT)
-#define R_SENS_PARAMS_QNT (sizeof(MB_SensorParamsTypeDef)/sizeof(uint16_t))
+#define R_SENS_PARAMS_ADDR (DS18B20_DEVICE_AMOUNT) // 30
+#define R_SENS_PARAMS_QNT (sizeof(MB_SensorParamsTypeDef)/sizeof(uint16_t)) // 7
+#define R_ALL_ROMS_ADDR (R_SENS_PARAMS_ADDR+R_SENS_PARAMS_QNT + 1) // 38
+#define R_ALL_ROMS_QNT (DS18B20_DEVICE_AMOUNT*4)
// DEFINES FOR HOLDING REGISTERS ARRAYS
#define R_SENS_INIT_ADDR (0)
@@ -119,6 +123,7 @@ typedef struct //MB_DataCoilsTypeDef
/* reg 2 - settings */
unsigned ConvertionDone:1;
unsigned LostedSensors:1;
+ unsigned reserved2:11;
}MB_DataCoilsTypeDef;
// DEFINES FOR COIL ARRAYS
@@ -126,7 +131,7 @@ typedef struct //MB_DataCoilsTypeDef
#define C_CONTROL_QNT 5
#define C_FLAGS_ADDR 16
-#define C_FLAGS_QNT 2
+#define C_FLAGS_QNT 10
/** MODBUS_DATA_COILS_DEFINES
* @}
diff --git a/Core/PY32Module/PY32module_main.c b/Core/PY32Module/PY32module_main.c
index 8cd6dbd..f1e7181 100644
--- a/Core/PY32Module/PY32module_main.c
+++ b/Core/PY32Module/PY32module_main.c
@@ -32,15 +32,21 @@ void PYModule_main(void)
}
}
- if(MB_DATA.Coils.ScanSensors)
+ if(MB_DATA.Coils.ReadSensor)
{
- PYModule_ScanSensor(&DallasBus);
- }
- else
- {
- scan_cnt = 0;
+ PYModule_ReadSensor(&hdallas1, &pchsens);
+ MB_DATA.Coils.ReadSensor = 0;
}
+// if(MB_DATA.Coils.ScanSensors)
+// {
+// PYModule_ScanSensor(&DallasBus);
+// }
+// else
+// {
+// scan_cnt = 0;
+// }
+
if(MB_DATA.Coils.InitSensor)
{
PYModule_InitSensor(&pchsens);
@@ -79,8 +85,9 @@ void PYModule_FirstInit(void)
OW.DataPort = DS_GPIO_Port;
/* Инициализация onewire и поиск датчиков*/
+ DS = (DS18B20_Drv_t *)&MB_DATA.InRegs.AllROMs;
OneWire_Init(&OW);
- DS18B20_Search(&DS, &OW);
+ DS18B20_Search(DS, &OW);
/* Инициализация modbus */
@@ -90,13 +97,13 @@ void PYModule_FirstInit(void)
/* Инициализация структур датчиков ПЧ */
DallasBus.hdallas = &hdallas1;
DallasBus.hdallas->onewire = &OW;
- DallasBus.hdallas->ds_devices = &DS;
+ DallasBus.hdallas->ds_devices = DS;
PCHSens_InitModule(&hdallas1, &pchsens.module1, REG_PCH_NUMB_11|REG_PCH_DIODE_NUMB_1);
- PCHSens_InitModule(&hdallas1, &pchsens.module2, REG_PCH_NUMB_12|REG_PCH_DIODE_NUMB_1);
- PCHSens_InitModule(&hdallas1, &pchsens.module3, REG_PCH_NUMB_21|REG_PCH_DIODE_NUMB_1);
- PCHSens_InitModule(&hdallas1, &pchsens.module4, REG_PCH_NUMB_22|REG_PCH_DIODE_NUMB_1);
- PCHSens_InitModule(&hdallas1, &pchsens.module5, REG_PCH_NUMB_31|REG_PCH_DIODE_NUMB_1);
- PCHSens_InitModule(&hdallas1, &pchsens.module6, REG_PCH_NUMB_32|REG_PCH_DIODE_NUMB_1);
+// PCHSens_InitModule(&hdallas1, &pchsens.module2, REG_PCH_NUMB_12|REG_PCH_DIODE_NUMB_1);
+// PCHSens_InitModule(&hdallas1, &pchsens.module3, REG_PCH_NUMB_21|REG_PCH_DIODE_NUMB_1);
+// PCHSens_InitModule(&hdallas1, &pchsens.module4, REG_PCH_NUMB_22|REG_PCH_DIODE_NUMB_1);
+// PCHSens_InitModule(&hdallas1, &pchsens.module5, REG_PCH_NUMB_31|REG_PCH_DIODE_NUMB_1);
+// PCHSens_InitModule(&hdallas1, &pchsens.module6, REG_PCH_NUMB_32|REG_PCH_DIODE_NUMB_1);
/* Поиск неизвестных сенсоров */
PCHSens_FindUnknownSensors(&DallasBus);
@@ -183,10 +190,11 @@ void PYModule_InitSensor(PCHSens_TypeDef *pchsens)
if(PCHSens_GetSensorByLocation(pchsens, (PCHSens_LocationTypeDef)MB_DATA.HoldRegs.InitStruct.Location, &sensor) != HAL_OK)
return;
uint64_t connectROM = 0;
- connectROM = ((uint64_t)(MB_DATA.HoldRegs.InitStruct.ROM[0]))<<48;
- connectROM |= ((uint64_t)(MB_DATA.HoldRegs.InitStruct.ROM[1]))<<32;
- connectROM |= ((uint64_t)(MB_DATA.HoldRegs.InitStruct.ROM[2]))<<16;
- connectROM |= ((uint64_t)(MB_DATA.HoldRegs.InitStruct.ROM[3]));
+ connectROM = ((uint64_t)(__REV16(MB_DATA.HoldRegs.InitStruct.ROM[0])))<<48;
+ connectROM |= ((uint64_t)(__REV16(MB_DATA.HoldRegs.InitStruct.ROM[1])))<<32;
+ connectROM |= ((uint64_t)(__REV16(MB_DATA.HoldRegs.InitStruct.ROM[2])))<<16;
+ connectROM |= ((uint64_t)(__REV16(MB_DATA.HoldRegs.InitStruct.ROM[3])));
+
if(PCHSens_InitNewSensor(&hdallas1, sensor, connectROM) == HAL_OK)
{
PYModule_FillResponse(sensor, STATUS_OK);
@@ -207,7 +215,7 @@ void PYModule_DeInitSensor(PCHSens_TypeDef *pchsens)
if(PCHSens_GetSensorByLocation(pchsens, (PCHSens_LocationTypeDef)MB_DATA.HoldRegs.InitStruct.Location, &sensor) != HAL_OK)
return;
- if(PCHSens_UndefineSensor(sensor) != HAL_OK)
+ if(PCHSens_UndefineSensor(sensor) == HAL_OK)
{
PYModule_FillResponse(sensor, STATUS_OK);
}
diff --git a/MDK-ARM/PY32Dallas.uvoptx b/MDK-ARM/PY32Dallas.uvoptx
index df7ffaf..d6db912 100644
--- a/MDK-ARM/PY32Dallas.uvoptx
+++ b/MDK-ARM/PY32Dallas.uvoptx
@@ -153,7 +153,56 @@
(105=-1,-1,-1,-1,0)
-
+
+
+ 0
+ 0
+ 201
+ 1
+ 134234866
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ ..\Core\PY32Module\PY32module_main.c
+
+ \\Project\../Core/PY32Module/PY32module_main.c\201
+
+
+ 1
+ 0
+ 197
+ 1
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ ..\Core\PY32Module\PY32module_main.c
+
+
+
+
+ 2
+ 0
+ 198
+ 1
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ ..\Core\PY32Module\PY32module_main.c
+
+
+
+
0
@@ -168,92 +217,52 @@
2
1
- module2
+ ROM
3
1
- *(volatile uint32_t *)0xE0001000
+ hmodbus1,0x10
4
1
- scratchpad
+ RS_Buffer,0x10
5
1
- ROM
+ mb_location
6
1
- start,0x0A
+ *(uint64_t *)(ROM)
7
1
- end,0x0A
+ *ROM
8
1
- (uint16_t)htim1.Instance->CNT-start,0x0A
+ sensor->sensROM
9
1
- end-start,0x0A
+ sensor
10
1
- ((uint16_t)htim1.Instance->CNT-start <(end-start)),0x0A
+ (uint64_t *)(ROM)
11
1
- ((uint16_t)htim1.Instance->CNT-start < us*tim_1us_period),0x0A
-
-
- 12
- 1
- (uint16_t)htim1.Instance->CNT-start,0x0A
-
-
- 13
- 1
- hmodbus1,0x0A
-
-
- 14
- 1
- RS_Buffer,0x10
-
-
- 15
- 1
- mb_location
-
-
- 16
- 1
- DS
-
-
- 17
- 1
- \\Project\../Core/PY32Module/PY32module_main.c\pchsens.module3
-
-
- 18
- 1
- \\Project\../Core/PY32Module/PY32module_main.c\pchsens.module4
-
-
- 19
- 1
- scan_cnt
+ (uint32_t *)(0x20000076)
@@ -265,24 +274,22 @@
1
2
- DS,0x10
+ MB_DATA,0x10
2
2
- OW
-
-
- 3
- 2
- MB_DATA,0x10
-
-
- 4
- 2
hmodbus1
+
+
+ 1
+ 0
+ 0x20000058-2
+ 0
+
+
0