Сделано базовое управление по модбас
- сохранение температур в модбас - чтение параметров датчика - инициализация нового датчика - деинициализация старого датчика Проект связанный с PY32модулем и температурами ПЧ перенесен в отдельную папку
This commit is contained in:
@@ -55,7 +55,7 @@ HAL_StatusTypeDef Dallas_ReplaceLostedSensor(DALLAS_SensorHandleTypeDef *sensor)
|
||||
|
||||
/**
|
||||
* @brief Функция для иниицализации нового датчика в структуре
|
||||
* @param onewire Указатель на структуру OneWire
|
||||
* @param hdallas Указатель на хендл для общения с датчиками
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @retval HAL Status
|
||||
*/
|
||||
@@ -79,7 +79,7 @@ HAL_StatusTypeDef Dallas_AddNewSensors(DALLAS_HandleTypeDef *hdallas, DALLAS_Sen
|
||||
|
||||
/**
|
||||
* @brief Инициализирует структуру датчика по ROM
|
||||
* @param onewire Указатель на структуру OneWire
|
||||
* @param hdallas Указатель на хендл для общения с датчиками
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @retval HAL Status
|
||||
*/
|
||||
@@ -141,7 +141,7 @@ HAL_StatusTypeDef Dallas_SensorInitByROM(DALLAS_HandleTypeDef *hdallas, DALLAS_S
|
||||
|
||||
/**
|
||||
* @brief Инициализирует структуру датчика по пользовательским байтам
|
||||
* @param onewire Указатель на структуру OneWire
|
||||
* @param hdallas Указатель на хендл для общения с датчиками
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @retval HAL Status
|
||||
*/
|
||||
@@ -211,7 +211,7 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(DALLAS_HandleTypeDef *hdallas, DA
|
||||
|
||||
/**
|
||||
* @brief Инициализирует структуру датчика по порядковому номеру
|
||||
* @param onewire Указатель на структуру OneWire
|
||||
* @param hdallas Указатель на хендл для общения с датчиками
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @retval HAL Status
|
||||
* @details Порядковый номер датчика в списке найденных.
|
||||
@@ -233,7 +233,7 @@ HAL_StatusTypeDef Dallas_SensorInitByInd(DALLAS_HandleTypeDef *hdallas, DALLAS_S
|
||||
|
||||
/**
|
||||
* @brief Инициализирует датчик для работы
|
||||
* @param onewire Указатель на структуру OneWire
|
||||
* @param hdallas Указатель на хендл для общения с датчиками
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @param ROM ROM датчика, который надо инициализировать
|
||||
* @retval HAL Status
|
||||
@@ -254,7 +254,7 @@ HAL_StatusTypeDef Dallas_SensorInit(DALLAS_HandleTypeDef *hdallas, DALLAS_Sensor
|
||||
// sensor->sensROM |= ((uint64_t)(*ROM)[i] << (56 - 8*i));
|
||||
|
||||
/* Проверка присутствует ли выбранный датчик на линии */
|
||||
result = DS18B20_ReadScratchpad(hdallas->onewire, (uint8_t *)&sensor->sensROM, (uint8_t *)&hdallas->scratchpad);
|
||||
result = Dallas_ReadScratchpad(sensor);
|
||||
if (result == HAL_OK)
|
||||
{
|
||||
/* Установка разрешения */
|
||||
@@ -279,9 +279,7 @@ HAL_StatusTypeDef Dallas_SensorInit(DALLAS_HandleTypeDef *hdallas, DALLAS_Sensor
|
||||
|
||||
/**
|
||||
* @brief Деинициализирует структуру датчика
|
||||
* @param onewire Указатель на структуру OneWire
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @param sens_ind Порядковый номер датчика в структуре
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_SensorDeInit(DALLAS_SensorHandleTypeDef *sensor)
|
||||
@@ -300,7 +298,7 @@ HAL_StatusTypeDef Dallas_SensorDeInit(DALLAS_SensorHandleTypeDef *sensor)
|
||||
|
||||
/**
|
||||
* @brief Запускает измерение температуры на всех датчиках
|
||||
* @param onewire Указатель на структуру OneWire
|
||||
* @param hdallas Указатель на хендл для общения с датчиками
|
||||
* @param waitCondition Условие ожидания завершения преобразования
|
||||
* @param dallas_delay_ms Время ожидания окончания конверсии
|
||||
* @retval HAL Status
|
||||
@@ -483,11 +481,10 @@ HAL_StatusTypeDef Dallas_ReadTemperature(DALLAS_SensorHandleTypeDef *sensor)
|
||||
HAL_StatusTypeDef Dallas_IsConnected(DALLAS_SensorHandleTypeDef *sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
if(sensor->isInitialized == 0)
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
result = DS18B20_ReadScratchpad(sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM, (uint8_t *)&sensor->hdallas->scratchpad);
|
||||
|
||||
result = Dallas_ReadScratchpad(sensor);
|
||||
|
||||
if (result == HAL_OK)
|
||||
{
|
||||
@@ -501,8 +498,8 @@ HAL_StatusTypeDef Dallas_IsConnected(DALLAS_SensorHandleTypeDef *sensor)
|
||||
if(sensor->isConnected == 1)
|
||||
{
|
||||
sensor->f.disconnect_cnt++;
|
||||
sensor->isLost = 1;
|
||||
}
|
||||
sensor->isLost = 1;
|
||||
sensor->isConnected = 0;
|
||||
|
||||
// Dallas_ReplaceLostedSensor(sensor);
|
||||
@@ -522,6 +519,8 @@ HAL_StatusTypeDef Dallas_IsConnected(DALLAS_SensorHandleTypeDef *sensor)
|
||||
HAL_StatusTypeDef Dallas_WriteUserBytes(DALLAS_SensorHandleTypeDef *sensor, uint16_t UserBytes12, uint16_t UserBytes34, uint8_t UserBytesMask)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
if(sensor->isInitialized == 0)
|
||||
return HAL_ERROR;
|
||||
@@ -537,7 +536,7 @@ HAL_StatusTypeDef Dallas_WriteUserBytes(DALLAS_SensorHandleTypeDef *sensor, uint
|
||||
sensor->f.write_err_cnt++;
|
||||
return result;
|
||||
}
|
||||
result = DS18B20_ReadScratchpad(sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM, (uint8_t *)&sensor->hdallas->scratchpad);
|
||||
result = Dallas_ReadScratchpad(sensor);
|
||||
if (result != HAL_OK)
|
||||
{
|
||||
return result;
|
||||
@@ -547,3 +546,9 @@ HAL_StatusTypeDef Dallas_WriteUserBytes(DALLAS_SensorHandleTypeDef *sensor, uint
|
||||
}
|
||||
|
||||
|
||||
HAL_StatusTypeDef Dallas_ReadScratchpad(DALLAS_SensorHandleTypeDef *sensor)
|
||||
{
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
return DS18B20_ReadScratchpad(sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM, (uint8_t *)&sensor->hdallas->scratchpad);
|
||||
}
|
||||
|
||||
@@ -140,6 +140,8 @@ HAL_StatusTypeDef Dallas_ReadTemperature(DALLAS_SensorHandleTypeDef *sensor);
|
||||
HAL_StatusTypeDef Dallas_IsConnected(DALLAS_SensorHandleTypeDef *sensor);
|
||||
/* Записывает пользовательские байты */
|
||||
HAL_StatusTypeDef Dallas_WriteUserBytes(DALLAS_SensorHandleTypeDef *sensor, uint16_t UserBytes12, uint16_t UserBytes34, uint8_t UserBytesMask);
|
||||
/* Записывает пользовательские байты */
|
||||
HAL_StatusTypeDef Dallas_ReadScratchpad(DALLAS_SensorHandleTypeDef *sensor);
|
||||
|
||||
|
||||
#endif // #ifndef DALLAS_TOOLS_H
|
||||
@@ -352,6 +352,22 @@ HAL_StatusTypeDef DS18B20_WaitForEndConvertion(OneWire_t* OW)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The function is used to wait for end of convertion without blocking
|
||||
* @param OW OneWire HandleTypedef
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_WaitForEndConvertion_NonBlocking(OneWire_t* OW)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* If line is pull down - conversion is ongoing */
|
||||
if(OneWire_ReadBit(OW) == 0)
|
||||
return HAL_BUSY;
|
||||
else
|
||||
return HAL_OK; // convertion done
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The function is used as set temperature alarm range on
|
||||
|
||||
@@ -89,6 +89,7 @@ HAL_StatusTypeDef DS18B20_StartConvTAll(OneWire_t* OW);
|
||||
HAL_StatusTypeDef DS18B20_CalcTemperature(OneWire_t* OW, uint8_t *ROM, uint8_t *Scratchpad, float *destination);
|
||||
HAL_StatusTypeDef DS18B20_ReadScratchpad(OneWire_t* OW, uint8_t *ROM, uint8_t *Scratchpad);
|
||||
HAL_StatusTypeDef DS18B20_WaitForEndConvertion(OneWire_t* OW);
|
||||
HAL_StatusTypeDef DS18B20_WaitForEndConvertion_NonBlocking(OneWire_t* OW);
|
||||
HAL_StatusTypeDef DS18B20_SetTempAlarm(OneWire_t* OW, uint8_t *ROM, int8_t Low,
|
||||
int8_t High);
|
||||
HAL_StatusTypeDef DS18B20_WriteUserBytes(OneWire_t* OW, uint8_t *ROM, int16_t UserBytes12,
|
||||
|
||||
@@ -281,6 +281,7 @@ MB_ExceptionTypeDef MB_DefineRegistersAddress(uint16_t **pRegs, uint16_t Addr, u
|
||||
if(MB_Check_Address_For_Arr(Addr, Qnt, R_TEMPERATURE_ADDR, R_TEMPERATURE_QNT) == NO_ERRORS)
|
||||
{
|
||||
*pRegs = MB_Set_Register_Ptr(&MB_DATA.InRegs, Addr); // начало регистров хранения/входных
|
||||
MB_DATA.Coils.ConvertionDone = 0; // сброс флага
|
||||
}
|
||||
// Параметры датчика
|
||||
else if(MB_Check_Address_For_Arr(Addr, Qnt, R_SENS_PARAMS_ADDR, R_SENS_PARAMS_QNT) == NO_ERRORS)
|
||||
|
||||
@@ -109,8 +109,9 @@ typedef struct //MB_DataCoilsTypeDef
|
||||
{
|
||||
/* reg 1 - control */
|
||||
unsigned RunConvertions:1;
|
||||
unsigned ReadSensor:1;
|
||||
unsigned InitSensor:1;
|
||||
unsigned DenitSensor:1;
|
||||
unsigned DeInitSensor:1;
|
||||
|
||||
unsigned reserved:13;
|
||||
|
||||
|
||||
297
Core/PY32Module/PY32module_main.c
Normal file
297
Core/PY32Module/PY32module_main.c
Normal file
@@ -0,0 +1,297 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file pch_sensors.c
|
||||
* @brief Работа с датчиками температуры DS18B20 в ПЧ
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
/* Includes ----------------------------------------------------------------*/
|
||||
|
||||
#include "PY32module_main.h"
|
||||
#include "rs_message.h"
|
||||
|
||||
/* Declarations and definitions --------------------------------------------*/
|
||||
PCHSens_TypeDef pchsens;
|
||||
|
||||
/* Functions ---------------------------------------------------------------*/
|
||||
|
||||
void PYModule_main(void)
|
||||
{
|
||||
|
||||
if(MB_DATA.Coils.RunConvertions)
|
||||
{
|
||||
if(DS18B20_WaitForEndConvertion_NonBlocking(hdallas1.onewire) == HAL_OK)
|
||||
{
|
||||
PCHSens_StartCovert(&DallasBus);
|
||||
GPIOA->ODR ^= GPIO_LED_2;
|
||||
}
|
||||
}
|
||||
|
||||
if(MB_DATA.Coils.ReadSensor)
|
||||
{
|
||||
PYModule_ReadSensor(&hdallas1, &pchsens);
|
||||
MB_DATA.Coils.ReadSensor = 0;
|
||||
}
|
||||
|
||||
if(MB_DATA.Coils.InitSensor)
|
||||
{
|
||||
PYModule_InitSensor(&pchsens);
|
||||
MB_DATA.Coils.InitSensor = 0;
|
||||
}
|
||||
|
||||
if(MB_DATA.Coils.DeInitSensor != NULL)
|
||||
{
|
||||
PYModule_DeInitSensor(&pchsens);
|
||||
MB_DATA.Coils.DeInitSensor = 0;
|
||||
}
|
||||
|
||||
PYModule_CheckLosted(&pchsens);
|
||||
|
||||
|
||||
if(MB_DATA.Coils.RunConvertions)
|
||||
{
|
||||
if(DS18B20_WaitForEndConvertion_NonBlocking(hdallas1.onewire) == HAL_OK)
|
||||
{
|
||||
PCHSens_ModuleReadTemperature(&pchsens.module1);
|
||||
// PCHSens_ModuleReadTemperature(&pchsens.module2);
|
||||
// PCHSens_ModuleReadTemperature(&pchsens.module3);
|
||||
// PCHSens_ModuleReadTemperature(&pchsens.module4);
|
||||
// PCHSens_ModuleReadTemperature(&pchsens.module5);
|
||||
// PCHSens_ModuleReadTemperature(&pchsens.module6);
|
||||
|
||||
PYModule_StoreModbus(&pchsens);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void PYModule_FirstInit(void)
|
||||
{
|
||||
OW.DataPin = DS_Pin;
|
||||
OW.DataPort = DS_GPIO_Port;
|
||||
DS.Resolution = DS18B20_RESOLUTION_9BITS;
|
||||
|
||||
/* Инициализация onewire и поиск датчиков*/
|
||||
OneWire_Init(&OW);
|
||||
DS18B20_Search(&DS, &OW);
|
||||
|
||||
|
||||
/* Инициализация modbus */
|
||||
MODBUS_FirstInit();
|
||||
RS_Receive_IT(&hmodbus1, &MODBUS_MSG);
|
||||
|
||||
/* Инициализация структур датчиков ПЧ */
|
||||
DallasBus.hdallas = &hdallas1;
|
||||
DallasBus.hdallas->onewire = &OW;
|
||||
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_13|REG_PCH_DIODE_NUMB_1);
|
||||
PCHSens_InitModule(&hdallas1, &pchsens.module4, REG_PCH_NUMB_21|REG_PCH_DIODE_NUMB_1);
|
||||
PCHSens_InitModule(&hdallas1, &pchsens.module5, REG_PCH_NUMB_22|REG_PCH_DIODE_NUMB_1);
|
||||
PCHSens_InitModule(&hdallas1, &pchsens.module6, REG_PCH_NUMB_23|REG_PCH_DIODE_NUMB_1);
|
||||
|
||||
/* Поиск неизвестных сенсоров */
|
||||
PCHSens_FindUnknownSensors(&DallasBus);
|
||||
|
||||
MB_DATA.Coils.RunConvertions = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PYModule_ReadSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_TypeDef *pchsens)
|
||||
{
|
||||
// чтение по локации
|
||||
if(MB_DATA.HoldRegs.InitStruct.Location != 0) // если локация не равна нулю
|
||||
{
|
||||
PCHSens_SensorTypeDef *sensor;
|
||||
|
||||
if(PCHSens_GetSensorByLocation(pchsens, (PCHSens_LocationTypeDef)MB_DATA.HoldRegs.InitStruct.Location, &sensor) != HAL_OK)
|
||||
return;
|
||||
|
||||
if(Dallas_ReadScratchpad(&sensor->sens) == HAL_OK)
|
||||
{
|
||||
MB_DATA.InRegs.Response.Location = *(uint16_t *)&sensor->sens.hdallas->scratchpad.tHighRegister;
|
||||
MB_DATA.InRegs.Response.Resolution = sensor->sens.hdallas->scratchpad.ConfigRegister;
|
||||
MB_DATA.InRegs.Response.ROM[0] = __REV16((sensor->sens.sensROM) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.ROM[1] = __REV16((sensor->sens.sensROM >> 16) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.ROM[2] = __REV16((sensor->sens.sensROM >> 32) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.ROM[3] = __REV16((sensor->sens.sensROM >> 48) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.Status = 0x1;
|
||||
}
|
||||
else
|
||||
{
|
||||
MB_DATA.InRegs.Response.Location = MB_DATA.HoldRegs.InitStruct.Location;
|
||||
MB_DATA.InRegs.Response.Resolution = 0;
|
||||
MB_DATA.InRegs.Response.ROM[0] = 0;
|
||||
MB_DATA.InRegs.Response.ROM[1] = 0;
|
||||
MB_DATA.InRegs.Response.ROM[2] = 0;
|
||||
MB_DATA.InRegs.Response.ROM[3] = 0;
|
||||
MB_DATA.InRegs.Response.Status = 0xFF;
|
||||
}
|
||||
}
|
||||
// чтение по ROM
|
||||
else if(MB_DATA.HoldRegs.InitStruct.ROM[0] | MB_DATA.HoldRegs.InitStruct.ROM[1] | // если РОМ не равен нулю
|
||||
MB_DATA.HoldRegs.InitStruct.ROM[2] | MB_DATA.HoldRegs.InitStruct.ROM[3] != 0)
|
||||
{
|
||||
if(DS18B20_ReadScratchpad(hdallas->onewire, (uint8_t *)MB_DATA.HoldRegs.InitStruct.ROM, (uint8_t *)&hdallas->scratchpad) == HAL_OK)
|
||||
{
|
||||
MB_DATA.InRegs.Response.Location = *(uint16_t *)&hdallas->scratchpad.tHighRegister;
|
||||
MB_DATA.InRegs.Response.Resolution = hdallas->scratchpad.ConfigRegister;
|
||||
MB_DATA.InRegs.Response.ROM[0] = MB_DATA.HoldRegs.InitStruct.ROM[0];
|
||||
MB_DATA.InRegs.Response.ROM[1] = MB_DATA.HoldRegs.InitStruct.ROM[1];
|
||||
MB_DATA.InRegs.Response.ROM[2] = MB_DATA.HoldRegs.InitStruct.ROM[2];
|
||||
MB_DATA.InRegs.Response.ROM[3] = MB_DATA.HoldRegs.InitStruct.ROM[3];
|
||||
MB_DATA.InRegs.Response.Status = 0x1;
|
||||
}
|
||||
else
|
||||
{
|
||||
MB_DATA.InRegs.Response.Location = 0;
|
||||
MB_DATA.InRegs.Response.Resolution = 0;
|
||||
MB_DATA.InRegs.Response.ROM[0] = MB_DATA.HoldRegs.InitStruct.ROM[0];
|
||||
MB_DATA.InRegs.Response.ROM[1] = MB_DATA.HoldRegs.InitStruct.ROM[1];
|
||||
MB_DATA.InRegs.Response.ROM[2] = MB_DATA.HoldRegs.InitStruct.ROM[2];
|
||||
MB_DATA.InRegs.Response.ROM[3] = MB_DATA.HoldRegs.InitStruct.ROM[3];
|
||||
MB_DATA.InRegs.Response.Status = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void PYModule_InitSensor(PCHSens_TypeDef *pchsens)
|
||||
{
|
||||
if( (MB_DATA.HoldRegs.InitStruct.Location != 0) && // если локация не равна нулю
|
||||
(MB_DATA.HoldRegs.InitStruct.ROM[0] | MB_DATA.HoldRegs.InitStruct.ROM[1] | // И если РОМ не равен нулю
|
||||
MB_DATA.HoldRegs.InitStruct.ROM[2] | MB_DATA.HoldRegs.InitStruct.ROM[3] != 0) )
|
||||
{
|
||||
PCHSens_SensorTypeDef *sensor;
|
||||
|
||||
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]));
|
||||
if(PCHSens_InitNewSensor(&hdallas1, sensor, connectROM) == HAL_OK)
|
||||
{
|
||||
MB_DATA.InRegs.Response.Location = *(uint16_t *)&sensor->sens.hdallas->scratchpad.tHighRegister;
|
||||
MB_DATA.InRegs.Response.Resolution = sensor->sens.hdallas->scratchpad.ConfigRegister;
|
||||
MB_DATA.InRegs.Response.ROM[0] = __REV16((sensor->sens.sensROM) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.ROM[1] = __REV16((sensor->sens.sensROM >> 16) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.ROM[2] = __REV16((sensor->sens.sensROM >> 32) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.ROM[3] = __REV16((sensor->sens.sensROM >> 48) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.Status = 0x1;
|
||||
}
|
||||
else
|
||||
{
|
||||
MB_DATA.InRegs.Response.Location = MB_DATA.HoldRegs.InitStruct.Location;
|
||||
MB_DATA.InRegs.Response.Resolution = 0;
|
||||
MB_DATA.InRegs.Response.ROM[0] = MB_DATA.HoldRegs.InitStruct.ROM[0];
|
||||
MB_DATA.InRegs.Response.ROM[1] = MB_DATA.HoldRegs.InitStruct.ROM[1];
|
||||
MB_DATA.InRegs.Response.ROM[2] = MB_DATA.HoldRegs.InitStruct.ROM[2];
|
||||
MB_DATA.InRegs.Response.ROM[3] = MB_DATA.HoldRegs.InitStruct.ROM[3];
|
||||
MB_DATA.InRegs.Response.Status = 0xFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PYModule_DeInitSensor(PCHSens_TypeDef *pchsens)
|
||||
{
|
||||
if(MB_DATA.HoldRegs.InitStruct.Location != 0) // если локация не равна нулю
|
||||
{
|
||||
PCHSens_SensorTypeDef *sensor;
|
||||
|
||||
if(PCHSens_GetSensorByLocation(pchsens, (PCHSens_LocationTypeDef)MB_DATA.HoldRegs.InitStruct.Location, &sensor) != HAL_OK)
|
||||
return;
|
||||
|
||||
if(PCHSens_UndefineSensor(sensor) != HAL_OK)
|
||||
{
|
||||
MB_DATA.InRegs.Response.Location = *(uint16_t *)&sensor->sens.hdallas->scratchpad.tHighRegister;
|
||||
MB_DATA.InRegs.Response.Resolution = sensor->sens.hdallas->scratchpad.ConfigRegister;
|
||||
MB_DATA.InRegs.Response.ROM[0] = __REV16((sensor->sens.sensROM) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.ROM[1] = __REV16((sensor->sens.sensROM >> 16) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.ROM[2] = __REV16((sensor->sens.sensROM >> 32) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.ROM[3] = __REV16((sensor->sens.sensROM >> 48) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.Status = 0xFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
MB_DATA.InRegs.Response.Location = *(uint16_t *)&sensor->sens.hdallas->scratchpad.tHighRegister;
|
||||
MB_DATA.InRegs.Response.Resolution = sensor->sens.hdallas->scratchpad.ConfigRegister;
|
||||
MB_DATA.InRegs.Response.ROM[0] = __REV16((sensor->sens.sensROM) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.ROM[1] = __REV16((sensor->sens.sensROM >> 16) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.ROM[2] = __REV16((sensor->sens.sensROM >> 32) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.ROM[3] = __REV16((sensor->sens.sensROM >> 48) & 0xFFFF);
|
||||
MB_DATA.InRegs.Response.Status = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PYModule_CheckModuleLosted(PCHSens_ModuleTypeDef *module, uint8_t *losted_flag)
|
||||
{
|
||||
if(module->sens1.not_found)
|
||||
*losted_flag |= 1;
|
||||
if(module->sens2.not_found)
|
||||
*losted_flag |= 1;
|
||||
if(module->sens3.not_found)
|
||||
*losted_flag |= 1;
|
||||
if(module->sens4.not_found)
|
||||
*losted_flag |= 1;
|
||||
}
|
||||
void PYModule_CheckLosted(PCHSens_TypeDef *pchsens)
|
||||
{
|
||||
uint8_t losted = 0;
|
||||
|
||||
// module1
|
||||
PYModule_CheckModuleLosted(&pchsens->module1, &losted);
|
||||
PYModule_CheckModuleLosted(&pchsens->module2, &losted);
|
||||
PYModule_CheckModuleLosted(&pchsens->module3, &losted);
|
||||
PYModule_CheckModuleLosted(&pchsens->module4, &losted);
|
||||
PYModule_CheckModuleLosted(&pchsens->module5, &losted);
|
||||
PYModule_CheckModuleLosted(&pchsens->module6, &losted);
|
||||
|
||||
if(losted)
|
||||
MB_DATA.Coils.LostedSensors = 1;
|
||||
else
|
||||
MB_DATA.Coils.LostedSensors = 0;
|
||||
}
|
||||
|
||||
void PYModule_StoreModuleToModbus(PCHSens_ModuleTypeDef *module)
|
||||
{
|
||||
uint8_t mb_location;
|
||||
uint8_t pch_numb = (module->refLocation.param.PCHdig1 - 1)*3 + (module->refLocation.param.PCHdig2 - 1);
|
||||
pch_numb *= 4;
|
||||
|
||||
mb_location = pch_numb + module->sens1.Location.param.Location;
|
||||
if (mb_location < DS18B20_DEVICE_AMOUNT)
|
||||
MB_DATA.InRegs.SensTemperature[mb_location] = module->sens1.sens.temperature*100;
|
||||
|
||||
mb_location = pch_numb + module->sens2.Location.param.Location;
|
||||
if (mb_location < DS18B20_DEVICE_AMOUNT)
|
||||
MB_DATA.InRegs.SensTemperature[mb_location] = module->sens2.sens.temperature*100;
|
||||
|
||||
mb_location = pch_numb + module->sens3.Location.param.Location;
|
||||
if (mb_location < DS18B20_DEVICE_AMOUNT)
|
||||
MB_DATA.InRegs.SensTemperature[mb_location] = module->sens3.sens.temperature*100;
|
||||
|
||||
mb_location = pch_numb + module->sens4.Location.param.Location;
|
||||
if (mb_location < DS18B20_DEVICE_AMOUNT)
|
||||
MB_DATA.InRegs.SensTemperature[mb_location] = module->sens4.sens.temperature*100;
|
||||
}
|
||||
|
||||
void PYModule_StoreModbus(PCHSens_TypeDef *pchsens)
|
||||
{
|
||||
uint8_t losted = 0;
|
||||
|
||||
// module1
|
||||
PYModule_StoreModuleToModbus(&pchsens->module1);
|
||||
PYModule_StoreModuleToModbus(&pchsens->module2);
|
||||
PYModule_StoreModuleToModbus(&pchsens->module3);
|
||||
PYModule_StoreModuleToModbus(&pchsens->module4);
|
||||
PYModule_StoreModuleToModbus(&pchsens->module5);
|
||||
PYModule_StoreModuleToModbus(&pchsens->module6);
|
||||
|
||||
MB_DATA.Coils.ConvertionDone |= 1;
|
||||
}
|
||||
26
Core/PY32Module/PY32module_main.h
Normal file
26
Core/PY32Module/PY32module_main.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file pch_sensors.h
|
||||
* @brief Работа с датчиками температуры DS18B20 в ПЧ
|
||||
******************************************************************************
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef MODULE_MAIN_H
|
||||
#define MODULE_MAIN_H
|
||||
|
||||
/* Includes -----------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "pch_sensors.h"
|
||||
#include "modbus_data.h"
|
||||
|
||||
/* Declarations and definitions ---------------------------------------------*/
|
||||
|
||||
/* Functions ---------------------------------------------------------------*/
|
||||
void PYModule_main(void);
|
||||
void PYModule_FirstInit(void);
|
||||
void PYModule_ReadSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_TypeDef *pchsens);
|
||||
void PYModule_InitSensor(PCHSens_TypeDef *pchsens);
|
||||
void PYModule_DeInitSensor(PCHSens_TypeDef *pchsens);
|
||||
void PYModule_CheckLosted(PCHSens_TypeDef *pchsens);
|
||||
void PYModule_StoreModbus(PCHSens_TypeDef *pchsens);
|
||||
#endif // #ifndef MODULE_MAIN_H
|
||||
@@ -10,16 +10,9 @@
|
||||
#include "pch_sensors.h"
|
||||
#include "modbus_data.h"
|
||||
PCHSens_DallasBusHandle DallasBus;
|
||||
PCHSens_SensorActionsTypeDef action;
|
||||
|
||||
/* Declarations and definitions --------------------------------------------*/
|
||||
|
||||
PCHSens_ModuleTypeDef module1;
|
||||
PCHSens_ModuleTypeDef module2;
|
||||
PCHSens_ModuleTypeDef module3;
|
||||
PCHSens_ModuleTypeDef module4;
|
||||
PCHSens_ModuleTypeDef module5;
|
||||
PCHSens_ModuleTypeDef module6;
|
||||
|
||||
/* Functions ---------------------------------------------------------------*/
|
||||
HAL_StatusTypeDef PCHSens_InitNewSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_SensorTypeDef* sensor, uint64_t ROM)
|
||||
{
|
||||
@@ -73,8 +66,6 @@ HAL_StatusTypeDef PCHSens_AddSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_Senso
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
// sensor->UserBytes = (PCHSens_LocationTypeDef *)&sensor->sens.scratchpad.tHighRegister;
|
||||
|
||||
sensor->sens.Init.InitParam = sensor->Location.all;
|
||||
|
||||
sensor->sens.Init.init_func = &Dallas_SensorInitByUserBytes;
|
||||
@@ -102,7 +93,6 @@ HAL_StatusTypeDef PCHSens_InitModule(DALLAS_HandleTypeDef *hdallas, PCHSens_Modu
|
||||
|
||||
PCHSens_LocationTypeDef initlocation;
|
||||
initlocation.all = param;
|
||||
action.read = 1;
|
||||
|
||||
module->hdallas = hdallas;
|
||||
module->refLocation = initlocation;
|
||||
@@ -126,23 +116,37 @@ HAL_StatusTypeDef PCHSens_InitModule(DALLAS_HandleTypeDef *hdallas, PCHSens_Modu
|
||||
}
|
||||
|
||||
|
||||
HAL_StatusTypeDef PCHSens_ModuleHandleAction(PCHSens_ModuleTypeDef* module)
|
||||
HAL_StatusTypeDef PCHSens_ModuleReadTemperature(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);
|
||||
result = PCHSens_SensorHandleActions(module->hdallas, &module->sens4);
|
||||
|
||||
result = PCHSens_SensorReadTemperature(module->hdallas, &module->sens1);
|
||||
result = PCHSens_SensorReadTemperature(module->hdallas, &module->sens2);
|
||||
result = PCHSens_SensorReadTemperature(module->hdallas, &module->sens3);
|
||||
result = PCHSens_SensorReadTemperature(module->hdallas, &module->sens4);
|
||||
|
||||
return result;
|
||||
}
|
||||
HAL_StatusTypeDef PCHSens_Covert(PCHSens_DallasBusHandle *hbus)
|
||||
HAL_StatusTypeDef PCHSens_SensorReadTemperature(DALLAS_HandleTypeDef *hdallas, PCHSens_SensorTypeDef *sensor)
|
||||
{
|
||||
return Dallas_StartConvertTAll(hbus->hdallas, DALLAS_WAIT_BUS, 0);
|
||||
HAL_StatusTypeDef result;
|
||||
if(hdallas == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
result = PCHSens_ReadTemperature(sensor);
|
||||
if(result != HAL_OK)
|
||||
PCHSens_CheckSensor(hdallas, sensor);
|
||||
|
||||
return result;
|
||||
}
|
||||
HAL_StatusTypeDef PCHSens_StartCovert(PCHSens_DallasBusHandle *hbus)
|
||||
{
|
||||
return Dallas_StartConvertTAll(hbus->hdallas, DALLAS_WAIT_NONE, 0);
|
||||
}
|
||||
HAL_StatusTypeDef PCHSens_ReadTemperature(PCHSens_SensorTypeDef* sensor)
|
||||
{
|
||||
@@ -150,9 +154,10 @@ HAL_StatusTypeDef PCHSens_ReadTemperature(PCHSens_SensorTypeDef* sensor)
|
||||
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor->sens.isInitialized == 0)
|
||||
return HAL_ERROR;
|
||||
|
||||
result = Dallas_ReadTemperature(&sensor->sens);
|
||||
PCHSens_StoreToModbus(sensor);
|
||||
result = Dallas_ReadTemperature(&sensor->sens);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -163,12 +168,10 @@ HAL_StatusTypeDef PCHSens_CheckSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_Sen
|
||||
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor->sens.isInitialized == 0)
|
||||
return HAL_ERROR;
|
||||
|
||||
if((sensor->sens.isLost == 1))
|
||||
if((sensor->sens.isLost == 1) || (sensor->sens.isInitialized == 0))
|
||||
{
|
||||
if(Dallas_ReplaceLostedSensor(&sensor->sens) != HAL_OK)
|
||||
if(Dallas_ReplaceLostedSensor(&sensor->sens) == HAL_ERROR)
|
||||
{
|
||||
sensor->not_found = 1;
|
||||
}
|
||||
@@ -177,6 +180,10 @@ HAL_StatusTypeDef PCHSens_CheckSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_Sen
|
||||
sensor->not_found = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sensor->not_found = 0;
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
@@ -211,23 +218,6 @@ HAL_StatusTypeDef PCHSens_FindUnknownSensors(PCHSens_DallasBusHandle *hbus)
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
//HAL_StatusTypeDef PCHSens_DefineUnknownSensor(PCHSens_UnknownSensorsTypeDef *unknowns, PCHSens_SensorTypeDef *sensor)
|
||||
//{
|
||||
// HAL_StatusTypeDef result;
|
||||
// if(sensor == NULL)
|
||||
// return HAL_ERROR;
|
||||
//
|
||||
// if((unknowns->ROMtoDefine != NULL) && (unknowns->LocationtoDefine.all != NULL) && (unknowns->senstoDefine != NULL))
|
||||
// {
|
||||
// result = PCHSens_InitNewSensor(unknowns->onewire, unknowns->senstoDefine, unknowns->ROMtoDefine);
|
||||
// unknowns->ROMtoDefine = 0;
|
||||
// unknowns->LocationtoDefine.all = 0;
|
||||
// unknowns->senstoDefine = 0;
|
||||
// return result;
|
||||
// }
|
||||
// return HAL_OK;
|
||||
//}
|
||||
|
||||
HAL_StatusTypeDef PCHSens_UndefineSensor(PCHSens_SensorTypeDef *sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
@@ -244,70 +234,40 @@ HAL_StatusTypeDef PCHSens_UndefineSensor(PCHSens_SensorTypeDef *sensor)
|
||||
return result;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef PCHSens_SensorHandleActions(DALLAS_HandleTypeDef *hdallas, PCHSens_SensorTypeDef *sensor)
|
||||
HAL_StatusTypeDef PCHSens_GetSensorByLocation(PCHSens_TypeDef *pchsens, PCHSens_LocationTypeDef Location, PCHSens_SensorTypeDef **sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
PCHSens_ModuleTypeDef *module;
|
||||
uint8_t pch_numb = (Location.param.PCHdig1 - 1)*3 + (Location.param.PCHdig2 - 1);
|
||||
|
||||
if(action.connectROM != NULL)
|
||||
switch(pch_numb)
|
||||
{
|
||||
result = PCHSens_InitNewSensor(hdallas, sensor, action.connectROM);
|
||||
action.connectROM = 0;
|
||||
case 0:
|
||||
module = &pchsens->module1; break;
|
||||
case 1:
|
||||
module = &pchsens->module2; break;
|
||||
case 2:
|
||||
module = &pchsens->module3; break;
|
||||
case 3:
|
||||
module = &pchsens->module4; break;
|
||||
case 4:
|
||||
module = &pchsens->module5; break;
|
||||
case 5:
|
||||
module = &pchsens->module6; break;
|
||||
default:
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if(action.read != NULL)
|
||||
switch(Location.param.Location)
|
||||
{
|
||||
result = PCHSens_ReadTemperature(sensor);
|
||||
if(result != HAL_OK)
|
||||
PCHSens_CheckSensor(hdallas, sensor);
|
||||
case 0:
|
||||
*sensor = &module->sens1; break;
|
||||
case 1:
|
||||
*sensor = &module->sens2; break;
|
||||
case 2:
|
||||
*sensor = &module->sens3; break;
|
||||
case 3:
|
||||
*sensor = &module->sens4; break;
|
||||
}
|
||||
|
||||
if(action.deinit != NULL)
|
||||
{
|
||||
action.deinit = 0;
|
||||
result = PCHSens_UndefineSensor(sensor);
|
||||
}
|
||||
|
||||
return result;
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
void PCHSens_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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -120,10 +120,12 @@ typedef union
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned convertion;
|
||||
uint64_t connectROM;
|
||||
unsigned read;
|
||||
unsigned deinit;
|
||||
}PCHSens_SensorActionsTypeDef;
|
||||
extern PCHSens_SensorActionsTypeDef action;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -144,12 +146,6 @@ typedef struct
|
||||
PCHSens_LocationTypeDef refLocation;
|
||||
|
||||
}PCHSens_ModuleTypeDef;
|
||||
extern PCHSens_ModuleTypeDef module1;
|
||||
extern PCHSens_ModuleTypeDef module2;
|
||||
extern PCHSens_ModuleTypeDef module3;
|
||||
extern PCHSens_ModuleTypeDef module4;
|
||||
extern PCHSens_ModuleTypeDef module5;
|
||||
extern PCHSens_ModuleTypeDef module6;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -159,17 +155,26 @@ typedef struct
|
||||
extern PCHSens_DallasBusHandle DallasBus;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PCHSens_ModuleTypeDef module1;
|
||||
PCHSens_ModuleTypeDef module2;
|
||||
PCHSens_ModuleTypeDef module3;
|
||||
PCHSens_ModuleTypeDef module4;
|
||||
PCHSens_ModuleTypeDef module5;
|
||||
PCHSens_ModuleTypeDef module6;
|
||||
}PCHSens_TypeDef;
|
||||
|
||||
/* Functions ---------------------------------------------------------------*/
|
||||
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_ModuleHandleAction(PCHSens_ModuleTypeDef* module);
|
||||
HAL_StatusTypeDef PCHSens_ModuleReadTemperature(PCHSens_ModuleTypeDef* module);
|
||||
HAL_StatusTypeDef PCHSens_SensorReadTemperature(DALLAS_HandleTypeDef *hdallas, PCHSens_SensorTypeDef *sensor);
|
||||
HAL_StatusTypeDef PCHSens_ReadTemperature(PCHSens_SensorTypeDef* sensor);
|
||||
HAL_StatusTypeDef PCHSens_Covert(PCHSens_DallasBusHandle *hbus);
|
||||
HAL_StatusTypeDef PCHSens_StartCovert(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);
|
||||
HAL_StatusTypeDef PCHSens_UndefineSensor(PCHSens_SensorTypeDef *sensor);
|
||||
HAL_StatusTypeDef PCHSens_GetSensorByLocation(PCHSens_TypeDef *pchsens, PCHSens_LocationTypeDef Location, PCHSens_SensorTypeDef **sensor);
|
||||
#endif // #ifndef PCH_SENSORS_H
|
||||
@@ -39,7 +39,7 @@ void MX_IWDG_Init(void)
|
||||
/* USER CODE END IWDG_Init 1 */
|
||||
hiwdg.Instance = IWDG;
|
||||
hiwdg.Init.Prescaler = IWDG_PRESCALER_32;
|
||||
hiwdg.Init.Reload = 100;
|
||||
hiwdg.Init.Reload = 1000;
|
||||
if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
#include "tim.h"
|
||||
#include "usart.h"
|
||||
#include "iwdg.h"
|
||||
#include "pch_sensors.h"
|
||||
#include "rs_message.h"
|
||||
#include "PY32module_main.h"
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
@@ -42,6 +41,7 @@ static void APP_SystemClockConfig(void);
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
__HAL_DBGMCU_FREEZE_IWDG();
|
||||
__HAL_DBGMCU_FREEZE_TIM1();
|
||||
__HAL_DBGMCU_FREEZE_TIM14();
|
||||
/* Reset of all peripherals, Initializes the Systick. */
|
||||
@@ -50,32 +50,19 @@ int main(void)
|
||||
/* System clock configuration */
|
||||
APP_SystemClockConfig();
|
||||
|
||||
MX_IWDG_Init();
|
||||
// MX_IWDG_Init();
|
||||
MX_GPIO_Init();
|
||||
MX_TIM1_Init();
|
||||
MX_TIM14_Init();
|
||||
MX_USART1_UART_Init();
|
||||
|
||||
MODBUS_FirstInit();
|
||||
RS_Receive_IT(&hmodbus1, &MODBUS_MSG);
|
||||
|
||||
|
||||
PCHSens_FirstInit();
|
||||
PYModule_FirstInit();
|
||||
/* infinite loop */
|
||||
while (1)
|
||||
{
|
||||
GPIOA->ODR ^= GPIO_LED_2;
|
||||
|
||||
|
||||
PCHSens_Covert(&DallasBus);
|
||||
|
||||
PCHSens_ModuleHandleAction(&module1);
|
||||
PCHSens_ModuleHandleAction(&module2);
|
||||
PCHSens_ModuleHandleAction(&module3);
|
||||
PCHSens_ModuleHandleAction(&module4);
|
||||
PCHSens_ModuleHandleAction(&module5);
|
||||
PCHSens_ModuleHandleAction(&module6);
|
||||
|
||||
PYModule_main();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user