Базово всё запущено. Датчики считываются записываются в модбас регистры, и по запросу выдаются.
Есть запас на 27-30 датчиков
This commit is contained in:
@@ -459,7 +459,9 @@ HAL_StatusTypeDef Dallas_ReadTemperature(DALLAS_SensorHandleTypeDef *sensor)
|
||||
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
|
||||
result = Dallas_IsConnected(sensor);
|
||||
if (result != HAL_OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
result = DS18B20_CalcTemperature(sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM, (uint8_t *)&sensor->hdallas->scratchpad, &sensor->temperature);
|
||||
@@ -495,7 +497,7 @@ HAL_StatusTypeDef Dallas_IsConnected(DALLAS_SensorHandleTypeDef *sensor)
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
sensor->temperature = 0;
|
||||
if(sensor->isConnected == 1)
|
||||
{
|
||||
sensor->f.disconnect_cnt++;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#define DS_GPIO_Port GPIOB
|
||||
|
||||
/* Data Structure ------------------------------------------------------------*/
|
||||
#define DS18B20_DEVICE_AMOUNT 27
|
||||
#define DS18B20_DEVICE_AMOUNT 30
|
||||
|
||||
/* Register ------------------------------------------------------------------*/
|
||||
#define DS18B20_CMD_CONVERT 0x44
|
||||
|
||||
@@ -119,8 +119,8 @@ void OneWire_Delay_uw(uint32_t us)
|
||||
{
|
||||
// start = htim1.Instance->CNT;
|
||||
// end = start + us*tim_1us_period;
|
||||
htim1.Instance->CNT = 0;
|
||||
TIM1->CNT = 0;
|
||||
end = us*tim_1us_period;
|
||||
|
||||
while(htim1.Instance->CNT < end) {};
|
||||
while(TIM1->CNT < end) {};
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
/* Includes ----------------------------------------------------------------*/
|
||||
|
||||
#include "pch_sensors.h"
|
||||
#include "modbus_data.h"
|
||||
PCHSens_DallasBusHandle DallasBus;
|
||||
PCHSens_SensorActionsTypeDef action;
|
||||
|
||||
@@ -111,8 +112,7 @@ HAL_StatusTypeDef PCHSens_InitModule(DALLAS_HandleTypeDef *hdallas, PCHSens_Modu
|
||||
PCHSens_AddSensor(hdallas, &module->sens1);
|
||||
|
||||
module->sens2.Location.all = module->refLocation.all;
|
||||
module->sens2.Location.param.Location = 1;
|
||||
|
||||
module->sens2.Location.param.Location = 1;
|
||||
PCHSens_AddSensor(hdallas, &module->sens2);
|
||||
|
||||
module->sens3.Location.all = module->refLocation.all;
|
||||
@@ -126,13 +126,13 @@ HAL_StatusTypeDef PCHSens_InitModule(DALLAS_HandleTypeDef *hdallas, PCHSens_Modu
|
||||
}
|
||||
|
||||
|
||||
HAL_StatusTypeDef PCHSens_ReadTemperature(PCHSens_ModuleTypeDef *module)
|
||||
HAL_StatusTypeDef PCHSens_ModuleHandleAction(PCHSens_ModuleTypeDef* module)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
if(module == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
|
||||
result = PCHSens_SensorHandleActions(module->hdallas, &module->sens1);
|
||||
result = PCHSens_SensorHandleActions(module->hdallas, &module->sens2);
|
||||
result = PCHSens_SensorHandleActions(module->hdallas, &module->sens3);
|
||||
@@ -140,15 +140,25 @@ HAL_StatusTypeDef PCHSens_ReadTemperature(PCHSens_ModuleTypeDef *module)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef PCHSens_Covert(PCHSens_DallasBusHandle *hbus)
|
||||
{
|
||||
return Dallas_StartConvertTAll(hbus->hdallas, DALLAS_WAIT_BUS, 0);
|
||||
}
|
||||
HAL_StatusTypeDef PCHSens_ReadTemperature(PCHSens_SensorTypeDef* sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
result = Dallas_ReadTemperature(&sensor->sens);
|
||||
PCHSens_StoreToModbus(sensor);
|
||||
|
||||
return result;
|
||||
}
|
||||
HAL_StatusTypeDef PCHSens_CheckSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_SensorTypeDef* sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
PCHSens_LocationTypeDef initlocation;
|
||||
unsigned unknow_sensors_flag = 0;
|
||||
|
||||
if(sensor == NULL)
|
||||
@@ -158,7 +168,6 @@ HAL_StatusTypeDef PCHSens_CheckSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_Sen
|
||||
|
||||
if((sensor->sens.isLost == 1))
|
||||
{
|
||||
initlocation.param.Location = 0;
|
||||
if(Dallas_ReplaceLostedSensor(&sensor->sens) != HAL_OK)
|
||||
{
|
||||
sensor->not_found = 1;
|
||||
@@ -249,7 +258,7 @@ HAL_StatusTypeDef PCHSens_SensorHandleActions(DALLAS_HandleTypeDef *hdallas, PCH
|
||||
|
||||
if(action.read != NULL)
|
||||
{
|
||||
result = Dallas_ReadTemperature(&sensor->sens);
|
||||
result = PCHSens_ReadTemperature(sensor);
|
||||
if(result != HAL_OK)
|
||||
PCHSens_CheckSensor(hdallas, sensor);
|
||||
}
|
||||
@@ -275,30 +284,30 @@ void PCHSens_FirstInit(void)
|
||||
|
||||
DallasBus.hdallas = &hdallas1;
|
||||
DallasBus.hdallas->onewire = &OW;
|
||||
|
||||
|
||||
|
||||
PCHSens_InitModule(&hdallas1, &module1, REG_PCH_NUMB_11|REG_PCH_DIODE_NUMB_1);
|
||||
PCHSens_InitModule(&hdallas1, &module2, REG_PCH_NUMB_12|REG_PCH_DIODE_NUMB_1);
|
||||
PCHSens_InitModule(&hdallas1, &module3, REG_PCH_NUMB_13|REG_PCH_DIODE_NUMB_1);
|
||||
PCHSens_InitModule(&hdallas1, &module4, REG_PCH_NUMB_21|REG_PCH_DIODE_NUMB_1);
|
||||
PCHSens_InitModule(&hdallas1, &module5, REG_PCH_NUMB_22|REG_PCH_DIODE_NUMB_1);
|
||||
PCHSens_InitModule(&hdallas1, &module6, REG_PCH_NUMB_23|REG_PCH_DIODE_NUMB_1);
|
||||
|
||||
PCHSens_FindUnknownSensors(&DallasBus);
|
||||
// PCHSens_DefineUnknownSensor(&UnknownSensors, NULL);
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
void PCHSens_StoreToModbus(PCHSens_SensorTypeDef *sensor)
|
||||
{
|
||||
uint8_t pch_numb = (sensor->Location.param.PCHdig1 - 1)*3 + (sensor->Location.param.PCHdig2 - 1);
|
||||
uint8_t location = (sensor->Location.param.Location);
|
||||
|
||||
uint8_t mb_location = pch_numb*4 + location;
|
||||
|
||||
if (mb_location < DS18B20_DEVICE_AMOUNT)
|
||||
MB_DATA.InRegs.SensTemperature[mb_location] = sensor->sens.temperature*100;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -163,11 +163,13 @@ extern PCHSens_DallasBusHandle DallasBus;
|
||||
HAL_StatusTypeDef PCHSens_InitNewSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_SensorTypeDef* sensor, uint64_t ROM);
|
||||
HAL_StatusTypeDef PCHSens_AddSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_SensorTypeDef* sensor);
|
||||
HAL_StatusTypeDef PCHSens_InitModule(DALLAS_HandleTypeDef *hdallas, PCHSens_ModuleTypeDef* module, uint16_t param);
|
||||
HAL_StatusTypeDef PCHSens_ReadTemperature(PCHSens_ModuleTypeDef *module);
|
||||
HAL_StatusTypeDef PCHSens_ModuleHandleAction(PCHSens_ModuleTypeDef* module);
|
||||
HAL_StatusTypeDef PCHSens_ReadTemperature(PCHSens_SensorTypeDef* sensor);
|
||||
HAL_StatusTypeDef PCHSens_Covert(PCHSens_DallasBusHandle *hbus);
|
||||
HAL_StatusTypeDef PCHSens_CheckSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_SensorTypeDef* sensor);
|
||||
HAL_StatusTypeDef PCHSens_FindUnknownSensors(PCHSens_DallasBusHandle *hbus);
|
||||
HAL_StatusTypeDef PCHSens_DefineUnknownSensor(PCHSens_DallasBusHandle *hbus, PCHSens_SensorTypeDef *sensor);
|
||||
HAL_StatusTypeDef PCHSens_SensorHandleActions(DALLAS_HandleTypeDef *hdallas, PCHSens_SensorTypeDef *sensor);
|
||||
void PCHSens_FirstInit(void);
|
||||
void PCHSens_StoreToModbus(PCHSens_SensorTypeDef *sensor);
|
||||
#endif // #ifndef PCH_SENSORS_H
|
||||
Reference in New Issue
Block a user