diff --git a/DS18B20/dallas_tools.c b/DS18B20/dallas_tools.c
index c0287f9..86ef68a 100644
--- a/DS18B20/dallas_tools.c
+++ b/DS18B20/dallas_tools.c
@@ -19,123 +19,7 @@
/* Declarations and definitions --------------------------------------------*/
-struct
-{
-DALLAS_HandleTypeDef outdoor;
-DALLAS_HandleTypeDef indoor;
-DALLAS_HandleTypeDef bathroom;
-DALLAS_HandleTypeDef kitchen;
-DALLAS_HandleTypeDef big_room;
-DALLAS_HandleTypeDef small_room;
-DALLAS_HandleTypeDef living_room;
-DALLAS_HandleTypeDef basement;
-}AllSens;
-
/* Functions ---------------------------------------------------------------*/
-
-void Dallas_ReadAll(void)
-{
- HAL_StatusTypeDef result;
-
- result = Dallas_StartConvertTAll(&OW, DALLAS_WAIT_BUS, 0);
-
- if(Dallas_ReadTemperature(&AllSens.outdoor) == HAL_BUSY)
- Dallas_ReplaceLostedSensor(&AllSens.outdoor);
-
- if(Dallas_ReadTemperature(&AllSens.indoor) == HAL_BUSY)
- Dallas_ReplaceLostedSensor(&AllSens.indoor);
-
- if(Dallas_ReadTemperature(&AllSens.bathroom) == HAL_BUSY)
- Dallas_ReplaceLostedSensor(&AllSens.bathroom);
-
- if(Dallas_ReadTemperature(&AllSens.kitchen) == HAL_BUSY)
- Dallas_ReplaceLostedSensor(&AllSens.kitchen);
-
- if(Dallas_ReadTemperature(&AllSens.big_room) == HAL_BUSY)
- Dallas_ReplaceLostedSensor(&AllSens.big_room);
-
- if(Dallas_ReadTemperature(&AllSens.small_room) == HAL_BUSY)
- Dallas_ReplaceLostedSensor(&AllSens.small_room);
-
- if(Dallas_ReadTemperature(&AllSens.living_room) == HAL_BUSY)
- Dallas_ReplaceLostedSensor(&AllSens.living_room);
-
- if(Dallas_ReadTemperature(&AllSens.basement) == HAL_BUSY)
- Dallas_ReplaceLostedSensor(&AllSens.basement);
-
-}
-
-void Dallas_FirstInit(void)
-{
- OW.DataPin = DS_Pin;
- OW.DataPort = DS_GPIO_Port;
- DS.Resolution = DS18B20_RESOLUTION_9BITS;
-
- OneWire_Init(&OW);
- DS18B20_Search(&DS, &OW);
- AllSens.outdoor.Init.ROM = 0x28C60C61060000DC;
- AllSens.indoor.Init.ROM = 0x283E4861060000F9;
- AllSens.bathroom.Init.ROM = 0x28876D60060000CD;
-
- AllSens.outdoor.Init.SensInd = 0;
- AllSens.indoor.Init.SensInd = 1;
- AllSens.bathroom.Init.SensInd = 2;
- AllSens.kitchen.Init.SensInd = 3;
- AllSens.big_room.Init.SensInd = 4;
- AllSens.small_room.Init.SensInd = 5;
- AllSens.living_room.Init.SensInd = 6;
- AllSens.basement.Init.SensInd = 7;
-
- AllSens.outdoor.Init.UserBytes12 = 1;
- AllSens.indoor.Init.UserBytes12 = 2;
- AllSens.bathroom.Init.UserBytes12 = 3;
- AllSens.kitchen.Init.UserBytes12 = 4;
- AllSens.big_room.Init.UserBytes12 = 5;
- AllSens.small_room.Init.UserBytes12 = 6;
- AllSens.living_room.Init.UserBytes12 = 7;
- AllSens.basement.Init.UserBytes12 = 8;
-
-
-
- AllSens.outdoor.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
- AllSens.indoor.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
- AllSens.bathroom.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
- AllSens.kitchen.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
- AllSens.big_room.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
- AllSens.small_room.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
- AllSens.living_room.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
- AllSens.basement.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
-
- Dallas_AddNewSensors(&OW, &AllSens.outdoor);
- Dallas_AddNewSensors(&OW, &AllSens.indoor);
- Dallas_AddNewSensors(&OW, &AllSens.bathroom);
-
-//
-// Dallas_SensorInitByInd(&OW, &AllSens.outdoor, 0);
-// Dallas_SensorInitByInd(&OW, &AllSens.indoor, 2);
-// Dallas_SensorInitByInd(&OW, &AllSens.bathroom, 1);
-// Dallas_SensorInitByInd(&OW, &AllSens.kitchen, 3);
-// Dallas_SensorInitByInd(&OW, &AllSens.big_room, 4);
-// Dallas_SensorInitByInd(&OW, &AllSens.small_room, 5);
-// Dallas_SensorInitByInd(&OW, &AllSens.living_room, 6);
-// Dallas_SensorInitByInd(&OW, &AllSens.basement, 7);
-//
-// uint8_t mask = DALLAS_USER_BYTE_ALL;
-// Dallas_WriteUserBytes(&AllSens.outdoor, 1, NULL, mask);
-// Dallas_WriteUserBytes(&AllSens.indoor, 2, NULL, mask);
-// Dallas_WriteUserBytes(&AllSens.bathroom, 3, NULL, mask);
-// Dallas_WriteUserBytes(&AllSens.kitchen, 4, NULL, mask);
-// Dallas_WriteUserBytes(&AllSens.big_room, 5, NULL, mask);
-// Dallas_WriteUserBytes(&AllSens.small_room, 6, NULL, mask);
-// Dallas_WriteUserBytes(&AllSens.living_room, 7, NULL, mask);
-// Dallas_WriteUserBytes(&AllSens.basement, 8, NULL, mask);
-}
-
-
-
-
-
-
/**
* @brief Функция для нахождения нового датчика на место потерянного
* @param sensor Указатель на структуру датчика
@@ -276,52 +160,47 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_Handle
DALLAS_ScratchpadTypeDef scratchpad;
for(int i = 0; i < onewire->RomCnt; i++)
- {
+ {
+ /* Проверка присутствует ли выбранный датчик на линии */
+ result = DS18B20_ReadScratchpad(onewire, (uint8_t *)&DS.DevAddr[i], (uint8_t *)&scratchpad);
+ if (result != HAL_OK)
+ return result;
- for(int rom_ind = 0; rom_ind < DALLAS_ROM_SIZE; rom_ind++)
+ /* Сравнение UserByte1 и UserByte2, если они не равны нулю */
+ if(sensor->Init.UserBytes12 != NULL)
{
- /* Проверка присутствует ли выбранный датчик на линии */
- result = DS18B20_ReadScratchpad(onewire, (uint8_t *)&DS.DevAddr[i], (uint8_t *)&scratchpad);
- if (result != HAL_OK)
- return result;
-
- /* Сравнение UserByte1 и UserByte2, если они не равны нулю */
- if(sensor->Init.UserBytes12 != NULL)
- {
- if( (scratchpad.tHighRegister == UserByte1) &&
- (scratchpad.tLowRegister == UserByte2))
- {
- UserByte12Cmp = 1;
- }
- }/* Если сравнение UserByte1 и UserByte2 не выбрано, то считаем что они совпадают */
- else
+ if( (scratchpad.tHighRegister == UserByte1) &&
+ (scratchpad.tLowRegister == UserByte2))
{
UserByte12Cmp = 1;
}
- /* Сравнение UserByte3 и UserByte4, если они не равны нулю */
- if(sensor->Init.UserBytes34 != NULL)
- {
- if( (scratchpad.UserByte3 == UserByte3) &&
- (scratchpad.UserByte4 == UserByte4))
- {
- UserByte34Cmp = 1;
- }
- }/* Если сравнение UserByte3 и UserByte4 не выбрано, то считаем что они одинаковые */
- else
+ }/* Если сравнение UserByte1 и UserByte2 не выбрано, то считаем что они совпадают */
+ else
+ {
+ UserByte12Cmp = 1;
+ }
+ /* Сравнение UserByte3 и UserByte4, если они не равны нулю */
+ if(sensor->Init.UserBytes34 != NULL)
+ {
+ if( (scratchpad.UserByte3 == UserByte3) &&
+ (scratchpad.UserByte4 == UserByte4))
{
UserByte34Cmp = 1;
}
- /* Если нашли нужный датчик - завершаем поиск */
- if(UserByte12Cmp && UserByte34Cmp)
- {
- // sensor->isInitialized = 1;
- // sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
- result = Dallas_SensorInit(onewire, sensor, &DS.DevAddr[i]);
- return result;
- }
+ }/* Если сравнение UserByte3 и UserByte4 не выбрано, то считаем что они одинаковые */
+ else
+ {
+ UserByte34Cmp = 1;
+ }
+ /* Если нашли нужный датчик - завершаем поиск */
+ if(UserByte12Cmp && UserByte34Cmp)
+ {
+// sensor->isInitialized = 1;
+// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
+ result = Dallas_SensorInit(onewire, sensor, &DS.DevAddr[i]);
+ return result;
}
}
- Dallas_SensorDeInit(sensor);
/* Возвращаем ошибку если не нашли */
return HAL_ERROR;
}
@@ -368,8 +247,6 @@ HAL_StatusTypeDef Dallas_SensorInit(OneWire_t *onewire, DALLAS_HandleTypeDef *se
if(onewire == 0)
return HAL_ERROR;
-
-
sensor->onewire = onewire;
for(int i = 0; i < DALLAS_ROM_SIZE; i++)
@@ -389,14 +266,12 @@ HAL_StatusTypeDef Dallas_SensorInit(OneWire_t *onewire, DALLAS_HandleTypeDef *se
else
{
sensor->isInitialized = 0;
- Dallas_SensorDeInit(sensor);
return result;
}
}
else
{
sensor->isInitialized = 0;
- Dallas_SensorDeInit(sensor);
return result;
}
}
@@ -414,12 +289,10 @@ HAL_StatusTypeDef Dallas_SensorDeInit(DALLAS_HandleTypeDef *sensor)
return HAL_ERROR;
DALLAS_InitStructTypeDef initbuff = sensor->Init;
- DALLAS_ControlTypeDef ctrlbuff = sensor->Control;
memset(sensor, 0, sizeof(DALLAS_HandleTypeDef));
sensor->Init = initbuff;
- sensor->Control = ctrlbuff;
return HAL_OK;
}
diff --git a/DS18B20/dallas_tools.h b/DS18B20/dallas_tools.h
index e0d8ad7..6587101 100644
--- a/DS18B20/dallas_tools.h
+++ b/DS18B20/dallas_tools.h
@@ -111,9 +111,7 @@ typedef enum
/* Functions ---------------------------------------------------------------*/
-void Dallas_Init(DALLAS_HandleTypeDef *sensor, UART_HandleTypeDef *huart);
-void Dallas_ReadAll(void);
-void Dallas_FirstInit(void);
+
/* Функция для нахождения нового датчика на место потерянного */
HAL_StatusTypeDef Dallas_ReplaceLostedSensor(DALLAS_HandleTypeDef *sensor);
/* Функция для иниицализации нового датчика в структуре */
diff --git a/DS18B20/pch_sensors.c b/DS18B20/pch_sensors.c
new file mode 100644
index 0000000..6656c9e
--- /dev/null
+++ b/DS18B20/pch_sensors.c
@@ -0,0 +1,173 @@
+/**
+******************************************************************************
+* @file pch_sensors.c
+* @brief Работа с датчиками температуры DS18B20 в ПЧ
+*****************************************************************************/
+
+
+/* Includes ----------------------------------------------------------------*/
+
+#include "pch_sensors.h"
+
+
+/* Declarations and definitions --------------------------------------------*/
+
+PCHSens_ModuleTypeDef module1;
+/* Functions ---------------------------------------------------------------*/
+
+HAL_StatusTypeDef PCHSens_InitNewSensor(OneWire_t *onewire, PCH_SensorTypeDef* sensor, uint64_t ROM, PCHSens_LocationTypeDef *location)
+{
+ DALLAS_HandleTypeDef tempsens;
+ HAL_StatusTypeDef result;
+ if(onewire == NULL)
+ return HAL_ERROR;
+ if(sensor == NULL)
+ return HAL_ERROR;
+ if(location == NULL)
+ return HAL_ERROR;
+
+ PCHSens_LocationTypeDef initlocation = *location;
+
+ sensor->Location = (PCHSens_LocationTypeDef *)&sensor->sens.scratchpad.tHighRegister;
+
+ sensor->sens.Init.ROM = ROM;
+
+ sensor->sens.Init.UserBytes12 = initlocation.all;
+
+ sensor->sens.Init.init_func = &Dallas_SensorInitByROM;
+
+ result = Dallas_AddNewSensors(onewire, &sensor->sens);
+ if(result != HAL_OK)
+ return result;
+
+ result = Dallas_WriteUserBytes(&sensor->sens, initlocation.all, 0, DALLAS_USER_BYTE_12);
+ if(result != HAL_OK)
+ return result;
+
+ sensor->sens.Init.init_func = &Dallas_SensorInitByUserBytes;
+
+ return Dallas_AddNewSensors(onewire, &sensor->sens);
+}
+
+
+HAL_StatusTypeDef PCHSens_FindSensor(OneWire_t *onewire, PCH_SensorTypeDef* sensor, PCHSens_LocationTypeDef *location)
+{
+ if(onewire == NULL)
+ return HAL_ERROR;
+ if(sensor == NULL)
+ return HAL_ERROR;
+ if(location == NULL)
+ return HAL_ERROR;
+
+ PCHSens_LocationTypeDef initlocation = *location;
+
+ sensor->Location = (PCHSens_LocationTypeDef *)&sensor->sens.scratchpad.tHighRegister;
+
+ sensor->sens.Init.UserBytes12 = initlocation.all;
+
+ sensor->sens.Init.init_func = &Dallas_SensorInitByUserBytes;
+
+ return Dallas_AddNewSensors(onewire, &sensor->sens);
+}
+
+HAL_StatusTypeDef PCHSens_FindModule(OneWire_t *onewire, PCHSens_ModuleTypeDef* module, PCHSens_LocationTypeDef *location, uint8_t init)
+{
+ if(onewire == NULL)
+ return HAL_ERROR;
+ if(module == NULL)
+ return HAL_ERROR;
+
+ PCHSens_LocationTypeDef initlocation = *location;
+
+ module->onewire = onewire;
+ module->refLocation = initlocation;
+
+ if(init == 0)
+ {
+ initlocation.location.Location = 0;
+ PCHSens_FindSensor(onewire, &module->sens1, &initlocation);
+
+ initlocation.location.Location = 1;
+ PCHSens_FindSensor(onewire, &module->sens2, &initlocation);
+
+ initlocation.location.Location = 2;
+ PCHSens_FindSensor(onewire, &module->sens3, &initlocation);
+
+ initlocation.location.Location = 3;
+ PCHSens_FindSensor(onewire, &module->sens4, &initlocation);
+ }
+ else
+ {
+ uint64_t ROM = 0x28366a48f6563c8d;
+ initlocation.location.Location = 0;
+ PCHSens_InitNewSensor(onewire, &module->sens1, ROM, &initlocation);
+
+ ROM = 0x28CF5248F6BB3C2F;
+ initlocation.location.Location = 1;
+ PCHSens_InitNewSensor(onewire, &module->sens2, ROM, &initlocation);
+
+ ROM = 0x28876D60060000CD;
+ initlocation.location.Location = 2;
+ PCHSens_InitNewSensor(onewire, &module->sens3, ROM, &initlocation);
+
+ ROM = 0;
+ initlocation.location.Location = 3;
+ PCHSens_InitNewSensor(onewire, &module->sens4, ROM, &initlocation);
+ }
+ return HAL_OK;
+}
+
+
+HAL_StatusTypeDef PCHSens_ReadModuleTemperature(PCHSens_ModuleTypeDef *module)
+{
+ HAL_StatusTypeDef result;
+
+ result = Dallas_StartConvertTAll(module->onewire, DALLAS_WAIT_BUS, 0);
+
+ result = Dallas_ReadTemperature(&module->sens1.sens);
+ result = Dallas_ReadTemperature(&module->sens2.sens);
+ result = Dallas_ReadTemperature(&module->sens3.sens);
+ result = Dallas_ReadTemperature(&module->sens4.sens);
+
+ return result;
+}
+
+void Dallas_FirstInit(void)
+{
+ int init_find = 0;
+ OW.DataPin = DS_Pin;
+ OW.DataPort = DS_GPIO_Port;
+ DS.Resolution = DS18B20_RESOLUTION_9BITS;
+
+ OneWire_Init(&OW);
+ DS18B20_Search(&DS, &OW);
+
+
+ PCHSens_LocationTypeDef location;
+ location.all = REG_PCH_NUMB_11|REG_PCH_DIODE_NUMB_1;
+ PCHSens_FindModule(&OW, &module1, &location, init_find);
+
+
+// Dallas_SensorInitByInd(&OW, &AllSens.outdoor, 0);
+// Dallas_SensorInitByInd(&OW, &AllSens.indoor, 2);
+// Dallas_SensorInitByInd(&OW, &AllSens.bathroom, 1);
+// Dallas_SensorInitByInd(&OW, &AllSens.kitchen, 3);
+// Dallas_SensorInitByInd(&OW, &AllSens.big_room, 4);
+// Dallas_SensorInitByInd(&OW, &AllSens.small_room, 5);
+// Dallas_SensorInitByInd(&OW, &AllSens.living_room, 6);
+// Dallas_SensorInitByInd(&OW, &AllSens.basement, 7);
+//
+// uint8_t mask = DALLAS_USER_BYTE_ALL;
+// Dallas_WriteUserBytes(&AllSens.outdoor, 1, NULL, mask);
+// Dallas_WriteUserBytes(&AllSens.indoor, 2, NULL, mask);
+// Dallas_WriteUserBytes(&AllSens.bathroom, 3, NULL, mask);
+// Dallas_WriteUserBytes(&AllSens.kitchen, 4, NULL, mask);
+// Dallas_WriteUserBytes(&AllSens.big_room, 5, NULL, mask);
+// Dallas_WriteUserBytes(&AllSens.small_room, 6, NULL, mask);
+// Dallas_WriteUserBytes(&AllSens.living_room, 7, NULL, mask);
+// Dallas_WriteUserBytes(&AllSens.basement, 8, NULL, mask);
+}
+
+
+
+
diff --git a/DS18B20/pch_sensors.h b/DS18B20/pch_sensors.h
new file mode 100644
index 0000000..55eda97
--- /dev/null
+++ b/DS18B20/pch_sensors.h
@@ -0,0 +1,117 @@
+/**
+******************************************************************************
+* @file pch_sensors.h
+* @brief Работа с датчиками температуры DS18B20 в ПЧ
+******************************************************************************
+*****************************************************************************/
+
+#ifndef PCH_SENSORS_H
+#define PCH_SENSORS_H
+
+
+
+/* Includes -----------------------------------------------------------------*/
+#include "stm32f1xx_hal.h"
+#include "dallas_tools.h"
+
+/* Declarations and definitions ---------------------------------------------*/
+
+/* Позиции параметров в ROM */
+#define REG_SENS_LOCATION_Pos (0) /*!< @brief Позиция параметра "Локация внутри модуля" */
+
+#define REG_PCH_LOCATION_Pos (8) /*!< @brief Позиция параметра "Расположение в ПЧ" */
+#define REG_PCH_DIOD_PHASE_Pos (10) /*!< @brief Позиция параметра "Диодный или фазный модуль" */
+#define REG_PCH_MODULE_NUMB_Pos (8) /*!< @brief Позиция параметра "Порядковый номер диодного/фазного модуля" */
+
+#define REG_PCH_NUMB_Pos (11) /*!< @brief Позиция параметра "Преобразователь частоты" */
+#define REG_PCH_NUMB_DIGIT_1_Pos (13) /*!< @brief Позиция параметра "Первая цифра номера преобразователя частоты" */
+#define REG_PCH_NUMB_DIGIT_2_Pos (11) /*!< @brief Позиция параметра "Вторая цифра номера преобразователя частоты" */
+
+#define REG_ZIP_Pos (15) /*!< @brief Позиция параметра "ЗИП/не ЗИП" */
+
+/* Маски параметров в ROM */
+#define REG_SENS_LOCATION_Mask ((uint16_t)0x3 << REG_SENS_LOCATION_Pos) /*!< @brief Маска параметра "Локация внутри модуля" */
+
+#define REG_PCH_LOCATION_Mask ((uint16_t)0x7 << REG_PCH_LOCATION_Pos) /*!< @brief Маска параметра "Расположение в ПЧ" */
+#define REG_PCH_DIOD_PHASE_Mask ((uint16_t)0x1 << REG_PCH_DIOD_PHASE_Pos) /*!< @brief Маска параметра "Диодный или фазный модуль" */
+#define REG_PCH_MODULE_NUMB_Mask ((uint16_t)0x3 << REG_PCH_MODULE_NUMB_Pos) /*!< @brief Маска параметра "Порядковый номер диодного/фазного модуля" */
+
+#define REG_PCH_NUMB_Mask ((uint16_t)0xF << REG_PCH_NUMB_Pos) /*!< @brief Маска параметра "Преобразователь частоты" */
+#define REG_PCH_NUMB_DIGIT_1_Mask ((uint16_t)0x3 << REG_PCH_NUMB_DIGIT_1_Pos) /*!< @brief Маска параметра "Первая цифра номера преобразователя частоты" */
+#define REG_PCH_NUMB_DIGIT_2_Mask ((uint16_t)0x3 << REG_PCH_NUMB_DIGIT_2_Pos) /*!< @brief Маска параметра "Вторая цифра номера преобразователя частоты" */
+
+#define REG_ZIP_Mask ((uint16_t)0x1 << REG_ZIP_Pos) /*!< @brief Маска параметра "ЗИП/не ЗИП" */
+
+/* Варианты параметров в ROM */
+#define REG_PCH_NUMB_11 ((1 << REG_PCH_NUMB_DIGIT_1_Pos) | (1 << REG_PCH_NUMB_DIGIT_2_Pos))
+#define REG_PCH_NUMB_12 ((1 << REG_PCH_NUMB_DIGIT_1_Pos) | (2 << REG_PCH_NUMB_DIGIT_2_Pos))
+#define REG_PCH_NUMB_13 ((1 << REG_PCH_NUMB_DIGIT_1_Pos) | (3 << REG_PCH_NUMB_DIGIT_2_Pos))
+#define REG_PCH_NUMB_21 ((2 << REG_PCH_NUMB_DIGIT_1_Pos) | (1 << REG_PCH_NUMB_DIGIT_2_Pos))
+#define REG_PCH_NUMB_22 ((2 << REG_PCH_NUMB_DIGIT_1_Pos) | (2 << REG_PCH_NUMB_DIGIT_2_Pos))
+#define REG_PCH_NUMB_23 ((2 << REG_PCH_NUMB_DIGIT_1_Pos) | (3 << REG_PCH_NUMB_DIGIT_2_Pos))
+
+#define REG_PCH_DIODE_NUMB_1 ((0 << REG_PCH_DIOD_PHASE_Pos) | (1 << REG_PCH_MODULE_NUMB_Pos))
+#define REG_PCH_DIODE_NUMB_2 ((0 << REG_PCH_DIOD_PHASE_Pos) | (2 << REG_PCH_MODULE_NUMB_Pos))
+#define REG_PCH_DIODE_NUMB_3 ((0 << REG_PCH_DIOD_PHASE_Pos) | (3 << REG_PCH_MODULE_NUMB_Pos))
+#define REG_PCH_PHASE_NUMB_1 ((1 << REG_PCH_DIOD_PHASE_Pos) | (1 << REG_PCH_MODULE_NUMB_Pos))
+#define REG_PCH_PHASE_NUMB_2 ((1 << REG_PCH_DIOD_PHASE_Pos) | (2 << REG_PCH_MODULE_NUMB_Pos))
+#define REG_PCH_PHASE_NUMB_3 ((1 << REG_PCH_DIOD_PHASE_Pos) | (3 << REG_PCH_MODULE_NUMB_Pos))
+
+/* Получить параметр из ROM */
+#define GET_REG_SENS_LOCATION(_REG_) ((_REG_) & REG_SENS_LOCATION_Mask) /*!< @brief Маска параметра "Локация внутри модуля" */
+
+#define GET_REG_PCH_LOCATION(_REG_) ((_REG_) & REG_PCH_LOCATION_Mask) /*!< @brief Маска параметра "Расположение в ПЧ" */
+#define GET_REG_PCH_DIOD_PHASE(_REG_) ((_REG_) & REG_PCH_DIOD_PHASE_Mask) /*!< @brief Маска параметра "Диодный или фазный модуль" */
+#define GET_REG_PCH_MODULE_NUMB(_REG_) ((_REG_) & REG_PCH_MODULE_NUMB_Mask) /*!< @brief Маска параметра "Порядковый номер диодного/фазного модуля" */
+
+#define GET_REG_PCH_NUMB(_REG_) ((_REG_) & REG_PCH_NUMB_Mask) /*!< @brief Маска параметра "Преобразователь частоты" */
+#define GET_REG_PCH_NUMB_DIGIT_1(_REG_) ((_REG_) & REG_PCH_NUMB_DIGIT_1_Mask) /*!< @brief Маска параметра "Первая цифра номера преобразователя частоты" */
+#define GET_REG_PCH_NUMB_DIGIT_2(_REG_) ((_REG_) & REG_PCH_NUMB_DIGIT_2_Mask) /*!< @brief Маска параметра "Вторая цифра номера преобразователя частоты" */
+
+#define GET_REG_ZIP(_REG_) ((_REG_) & REG_ZIP_Mask) /*!< @brief Маска параметра "ЗИП/не ЗИП" */
+
+
+typedef union
+{
+ uint16_t all;
+ struct
+ {
+ unsigned Location:2;
+ unsigned reserved:6;
+ unsigned ModuleNumb:2;
+ unsigned DiodeOrPhase:1;
+ unsigned PCHdig2:2;
+ unsigned PCHdig1:2;
+ unsigned ZIP:1;
+ }location;
+}PCHSens_LocationTypeDef;
+
+
+typedef struct
+{
+ DALLAS_HandleTypeDef sens;
+ PCHSens_LocationTypeDef *Location;
+}PCH_SensorTypeDef;
+
+typedef struct
+{
+ OneWire_t *onewire;
+
+ PCH_SensorTypeDef sens1;
+ PCH_SensorTypeDef sens2;
+ PCH_SensorTypeDef sens3;
+ PCH_SensorTypeDef sens4;
+
+ PCHSens_LocationTypeDef refLocation;
+}PCHSens_ModuleTypeDef;
+extern PCHSens_ModuleTypeDef module1;
+
+
+/* Functions ---------------------------------------------------------------*/
+HAL_StatusTypeDef PCHSens_InitNewSensor(OneWire_t *onewire, PCH_SensorTypeDef* sensor, uint64_t ROM, PCHSens_LocationTypeDef *location);
+HAL_StatusTypeDef PCHSens_FindSensor(OneWire_t *onewire, PCH_SensorTypeDef* sensor, PCHSens_LocationTypeDef *location);
+HAL_StatusTypeDef PCHSens_FindModule(OneWire_t *onewire, PCHSens_ModuleTypeDef* module, PCHSens_LocationTypeDef *location, uint8_t init);
+HAL_StatusTypeDef PCHSens_ReadModuleTemperature(PCHSens_ModuleTypeDef *module);
+
+void Dallas_FirstInit(void);
+#endif // #ifndef PCH_SENSORS_H
\ No newline at end of file
diff --git a/test_project/Core/Src/main.c b/test_project/Core/Src/main.c
index c4a4b8c..694b797 100644
--- a/test_project/Core/Src/main.c
+++ b/test_project/Core/Src/main.c
@@ -24,7 +24,7 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
-#include "dallas_tools.h"
+#include "pch_sensors.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@@ -103,16 +103,12 @@ int main(void)
/* USER CODE BEGIN WHILE */
while (1)
{
- Dallas_ReadAll();
+ PCHSens_ReadModuleTemperature(&module1);
+// Dallas_ReadAll();
/* Start temperature conversion on all devices on one bus */
// DS18B20_StartConvTAll(&OW);
// DS18B20_WaitForEndConvertion(&OW);
- /* Read temperature from device and store it to DS data structure */
- for(uint8_t i = 0; i < OW.RomCnt; i++)
- {
- /* Read Temperature */
-// DS18B20_CalcTemperature(&OW, DS.DevAddr[i], &DS.Temperature[i]);
- }
+
/* Search Alarm triggered and store in DS data structure */
// DS18B20_AlarmSearch(&DS, &OW);
diff --git a/test_project/MDK-ARM/ds18b20.uvoptx b/test_project/MDK-ARM/ds18b20.uvoptx
index 58ff380..66bd40e 100644
--- a/test_project/MDK-ARM/ds18b20.uvoptx
+++ b/test_project/MDK-ARM/ds18b20.uvoptx
@@ -152,23 +152,23 @@
0
0
- 366
+ 294
1
- 0
+ 134220332
0
0
0
0
0
- 0
+ 1
..\..\DS18B20\dallas_tools.c
-
+ \\ds18b20\../../DS18B20/dallas_tools.c\294
1
0
- 257
+ 291
1
0
0
@@ -196,54 +196,34 @@
2
1
- GPIO_InitStruct
+ ROM
3
1
- config
+ sensor
4
1
- outdoor
+ initlocation
5
1
- AllSens,0x10
-
-
- 6
- 1
- pin_numb
-
-
- 7
- 1
- usec,0x0A
+ scratchpad
0
2
- ROM
+ module1
1
2
- ROM[0]
-
-
- 2
- 2
- ROM[1]
-
-
- 3
- 2
- intROM
+ init_find
@@ -617,6 +597,30 @@
0
0
0
+ ..\..\DS18B20\pch_sensors.c
+ pch_sensors.c
+ 0
+ 0
+
+
+ 5
+ 24
+ 5
+ 0
+ 0
+ 0
+ ..\..\DS18B20\pch_sensors.h
+ pch_sensors.h
+ 0
+ 0
+
+
+ 5
+ 25
+ 1
+ 0
+ 0
+ 0
..\..\DS18B20\dallas_tools.c
dallas_tools.c
0
@@ -624,7 +628,7 @@
5
- 24
+ 26
5
0
0
@@ -636,7 +640,7 @@
5
- 25
+ 27
1
0
0
@@ -648,7 +652,7 @@
5
- 26
+ 28
5
0
0
@@ -660,7 +664,7 @@
5
- 27
+ 29
1
0
0
@@ -672,7 +676,7 @@
5
- 28
+ 30
5
0
0
@@ -684,7 +688,7 @@
5
- 29
+ 31
1
0
0
@@ -696,7 +700,7 @@
5
- 30
+ 32
5
0
0
@@ -708,7 +712,7 @@
5
- 31
+ 33
1
0
0
@@ -720,7 +724,7 @@
5
- 32
+ 34
5
0
0
diff --git a/test_project/MDK-ARM/ds18b20.uvprojx b/test_project/MDK-ARM/ds18b20.uvprojx
index 5475538..6d448fa 100644
--- a/test_project/MDK-ARM/ds18b20.uvprojx
+++ b/test_project/MDK-ARM/ds18b20.uvprojx
@@ -566,6 +566,16 @@
DS18B20
+
+ pch_sensors.c
+ 1
+ ..\..\DS18B20\pch_sensors.c
+
+
+ pch_sensors.h
+ 5
+ ..\..\DS18B20\pch_sensors.h
+
dallas_tools.c
1