/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "adc.h" #include "i2c.h" #include "rtc.h" #include "tim.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "dallas_tools.h" #include "def.h" #include #include "modbus.h" #include "eeprom_emul.h" #include "stdio.h" #include "flash_ring.h" #include "string.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ const uint8_t sin_table_phase_a[256] = { 127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 198, 201, 204, 207, 210, 212, 215, 218, 220, 223, 225, 228, 230, 233, 235, 238, 240, 242, 244, 247, 249, 251, 253, 255, 254, 252, 250, 248, 246, 244, 242, 240, 237, 235, 233, 230, 228, 225, 223, 220, 218, 215, 212, 210, 207, 204, 201, 198, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 157, 154, 151, 148, 145, 142, 139, 136, 133, 130, 127, 124, 121, 118, 115, 112, 109, 106, 103, 100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58, 55, 53, 50, 47, 44, 41, 39, 36, 33, 31, 28, 26, 23, 21, 18, 16, 13, 11, 9, 7, 4, 2, 0, 1, 3, 5, 7, 9, 11, 14, 16, 18, 21, 23, 26, 28, 31, 33, 36, 39, 41, 44, 47, 50, 53, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 103, 106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 198, 201, 204, 207, 210, 212, 215, 218, 220, 223, 225, 228, 230, 233, 235, 238, 240, 242, 244, 247, 249, 251, 253, 255, 254, 252, 250, 248, 246, 244, 242, 240, 237, 235, 233, 230, 228, 225, 223, 220, 218, 215, 212, 210 }; const uint8_t sin_table_phase_b[256] = { 210, 207, 204, 201, 198, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 157, 154, 151, 148, 145, 142, 139, 136, 133, 130, 127, 124, 121, 118, 115, 112, 109, 106, 103, 100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58, 55, 53, 50, 47, 44, 41, 39, 36, 33, 31, 28, 26, 23, 21, 18, 16, 13, 11, 9, 7, 4, 2, 0, 1, 3, 5, 7, 9, 11, 14, 16, 18, 21, 23, 26, 28, 31, 33, 36, 39, 41, 44, 47, 50, 53, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 103, 106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 198, 201, 204, 207, 210, 212, 215, 218, 220, 223, 225, 228, 230, 233, 235, 238, 240, 242, 244, 247, 249, 251, 253, 255, 254, 252, 250, 248, 246, 244, 242, 240, 237, 235, 233, 230, 228, 225, 223, 220, 218, 215, 212, 210, 207, 204, 201, 198, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 157, 154, 151, 148, 145, 142, 139, 136, 133, 130, 127, 124, 121, 118, 115, 112, 109, 106, 103, 100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58, 55, 53, 50, 47, 44, 41, 39, 36, 33, 31, 28, 26, 23, 21, 18, 16 }; const uint8_t sin_table_phase_c[256] = { 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 103, 106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 198, 201, 204, 207, 210, 212, 215, 218, 220, 223, 225, 228, 230, 233, 235, 238, 240, 242, 244, 247, 249, 251, 253, 255, 254, 252, 250, 248, 246, 244, 242, 240, 237, 235, 233, 230, 228, 225, 223, 220, 218, 215, 212, 210, 207, 204, 201, 198, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 157, 154, 151, 148, 145, 142, 139, 136, 133, 130, 127, 124, 121, 118, 115, 112, 109, 106, 103, 100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58, 55, 53, 50, 47, 44, 41, 39, 36, 33, 31, 28, 26, 23, 21, 18, 16, 13, 11, 9, 7, 4, 2, 0, 1, 3, 5, 7, 9, 11, 14, 16, 18, 21, 23, 26, 28, 31, 33, 36, 39, 41, 44, 47, 50, 53, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 103, 106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 198, 201, 204, 207, 210, 212, 215, 218, 220, 223, 225, 228, 230, 233, 235, 238, 240, 242, 244, 247 }; const uint8_t ramp_table[256] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 }; const uint8_t interleaved_tables[1024] = { 127, 210, 55, 0, // i=0: A0, B0, C0, R0 130, 207, 58, 1, // i=1: A1, B1, C1, R1 133, 204, 61, 2, // i=2: A2, B2, C2, R2 136, 201, 64, 3, // i=3: A3, B3, C3, R3 139, 198, 67, 4, // i=4 142, 196, 70, 5, // i=5 145, 193, 73, 6, // i=6 148, 190, 76, 7, // i=7 151, 187, 79, 8, // i=8 154, 184, 82, 9, // i=9 157, 181, 85, 10, // i=10 160, 178, 88, 11, // i=11 163, 175, 91, 12, // i=12 166, 172, 94, 13, // i=13 169, 169, 97, 14, // i=14 172, 166, 100, 15, // i=15 175, 163, 103, 16, // i=16 178, 160, 106, 17, // i=17 181, 157, 109, 18, // i=18 184, 154, 112, 19, // i=19 187, 151, 115, 20, // i=20 190, 148, 118, 21, // i=21 193, 145, 121, 22, // i=22 196, 142, 124, 23, // i=23 198, 139, 127, 24, // i=24 201, 136, 130, 25, // i=25 204, 133, 133, 26, // i=26 207, 130, 136, 27, // i=27 210, 127, 139, 28, // i=28 212, 124, 142, 29, // i=29 215, 121, 145, 30, // i=30 218, 118, 148, 31, // i=31 220, 115, 151, 32, // i=32 223, 112, 154, 33, // i=33 225, 109, 157, 34, // i=34 228, 106, 160, 35, // i=35 230, 103, 163, 36, // i=36 233, 100, 166, 37, // i=37 235, 97, 169, 38, // i=38 238, 94, 172, 39, // i=39 240, 91, 175, 40, // i=40 242, 88, 178, 41, // i=41 244, 85, 181, 42, // i=42 247, 82, 184, 43, // i=43 249, 79, 187, 44, // i=44 251, 76, 190, 45, // i=45 253, 73, 193, 46, // i=46 255, 70, 196, 47, // i=47 254, 67, 198, 48, // i=48 252, 64, 201, 49, // i=49 250, 61, 204, 50, // i=50 248, 58, 207, 51, // i=51 246, 55, 210, 52, // i=52 244, 53, 212, 53, // i=53 242, 50, 215, 54, // i=54 240, 47, 218, 55, // i=55 237, 44, 220, 56, // i=56 235, 41, 223, 57, // i=57 233, 39, 225, 58, // i=58 230, 36, 228, 59, // i=59 228, 33, 230, 60, // i=60 225, 31, 233, 61, // i=61 223, 28, 235, 62, // i=62 220, 26, 238, 63, // i=63 218, 23, 240, 64, // i=64 215, 21, 242, 65, // i=65 212, 18, 244, 66, // i=66 210, 16, 247, 67, // i=67 207, 13, 249, 68, // i=68 204, 11, 251, 69, // i=69 201, 9, 253, 70, // i=70 198, 7, 255, 71, // i=71 196, 4, 254, 72, // i=72 193, 2, 252, 73, // i=73 190, 0, 250, 74, // i=74 187, 1, 248, 75, // i=75 184, 3, 246, 76, // i=76 181, 5, 244, 77, // i=77 178, 7, 242, 78, // i=78 175, 9, 240, 79, // i=79 172, 11, 237, 80, // i=80 169, 14, 235, 81, // i=81 166, 16, 233, 82, // i=82 163, 18, 230, 83, // i=83 160, 21, 228, 84, // i=84 157, 23, 225, 85, // i=85 154, 26, 223, 86, // i=86 151, 28, 220, 87, // i=87 148, 31, 218, 88, // i=88 145, 33, 215, 89, // i=89 142, 36, 212, 90, // i=90 139, 39, 210, 91, // i=91 136, 41, 207, 92, // i=92 133, 44, 204, 93, // i=93 130, 47, 201, 94, // i=94 127, 50, 198, 95, // i=95 124, 53, 196, 96, // i=96 121, 55, 193, 97, // i=97 118, 58, 190, 98, // i=98 115, 61, 187, 99, // i=99 112, 64, 184, 100, // i=100 109, 67, 181, 101, // i=101 106, 70, 178, 102, // i=102 103, 73, 175, 103, // i=103 100, 76, 172, 104, // i=104 97, 79, 169, 105, // i=105 94, 82, 166, 106, // i=106 91, 85, 163, 107, // i=107 88, 88, 160, 108, // i=108 85, 91, 157, 109, // i=109 82, 94, 154, 110, // i=110 79, 97, 151, 111, // i=111 76, 100, 148, 112, // i=112 73, 103, 145, 113, // i=113 70, 106, 142, 114, // i=114 67, 109, 139, 115, // i=115 64, 112, 136, 116, // i=116 61, 115, 133, 117, // i=117 58, 118, 130, 118, // i=118 55, 121, 127, 119, // i=119 53, 124, 124, 120, // i=120 50, 127, 121, 121, // i=121 47, 130, 118, 122, // i=122 44, 133, 115, 123, // i=123 41, 136, 112, 124, // i=124 39, 139, 109, 125, // i=125 36, 142, 106, 126, // i=126 33, 145, 103, 127, // i=127 31, 148, 100, 128, // i=128 28, 151, 97, 129, // i=129 26, 154, 94, 130, // i=130 23, 157, 91, 131, // i=131 21, 160, 88, 132, // i=132 18, 163, 85, 133, // i=133 16, 166, 82, 134, // i=134 13, 169, 79, 135, // i=135 11, 172, 76, 136, // i=136 9, 175, 73, 137, // i=137 7, 178, 70, 138, // i=138 4, 181, 67, 139, // i=139 2, 184, 64, 140, // i=140 0, 187, 61, 141, // i=141 1, 190, 58, 142, // i=142 3, 193, 55, 143, // i=143 5, 196, 53, 144, // i=144 7, 198, 50, 145, // i=145 9, 201, 47, 146, // i=146 11, 204, 44, 147, // i=147 14, 207, 41, 148, // i=148 16, 210, 39, 149, // i=149 18, 212, 36, 150, // i=150 21, 215, 33, 151, // i=151 23, 218, 31, 152, // i=152 26, 220, 28, 153, // i=153 28, 223, 26, 154, // i=154 31, 225, 23, 155, // i=155 33, 228, 21, 156, // i=156 36, 230, 18, 157, // i=157 39, 233, 16, 158, // i=158 41, 235, 13, 159, // i=159 44, 238, 11, 160, // i=160 47, 240, 9, 161, // i=161 50, 242, 7, 162, // i=162 53, 244, 4, 163, // i=163 55, 247, 2, 164, // i=164 58, 249, 0, 165, // i=165 61, 251, 1, 166, // i=166 64, 253, 3, 167, // i=167 67, 255, 5, 168, // i=168 70, 254, 7, 169, // i=169 73, 252, 9, 170, // i=170 76, 250, 11, 171, // i=171 79, 248, 14, 172, // i=172 82, 246, 16, 173, // i=173 85, 244, 18, 174, // i=174 88, 242, 21, 175, // i=175 91, 240, 23, 176, // i=176 94, 237, 26, 177, // i=177 97, 235, 28, 178, // i=178 100, 233, 31, 179, // i=179 103, 230, 33, 180, // i=180 106, 228, 36, 181, // i=181 109, 225, 39, 182, // i=182 112, 223, 41, 183, // i=183 115, 220, 44, 184, // i=184 118, 218, 47, 185, // i=185 121, 215, 50, 186, // i=186 124, 212, 53, 187, // i=187 127, 210, 55, 188, // i=188 130, 207, 58, 189, // i=189 133, 204, 61, 190, // i=190 136, 201, 64, 191, // i=191 139, 198, 67, 192, // i=192 142, 196, 70, 193, // i=193 145, 193, 73, 194, // i=194 148, 190, 76, 195, // i=195 151, 187, 79, 196, // i=196 154, 184, 82, 197, // i=197 157, 181, 85, 198, // i=198 160, 178, 88, 199, // i=199 163, 175, 91, 200, // i=200 166, 172, 94, 201, // i=201 169, 169, 97, 202, // i=202 172, 166, 100, 203, // i=203 175, 163, 103, 204, // i=204 178, 160, 106, 205, // i=205 181, 157, 109, 206, // i=206 184, 154, 112, 207, // i=207 187, 151, 115, 208, // i=208 190, 148, 118, 209, // i=209 193, 145, 121, 210, // i=210 196, 142, 124, 211, // i=211 198, 139, 127, 212, // i=212 201, 136, 130, 213, // i=213 204, 133, 133, 214, // i=214 207, 130, 136, 215, // i=215 210, 127, 139, 216, // i=216 212, 124, 142, 217, // i=217 215, 121, 145, 218, // i=218 218, 118, 148, 219, // i=219 220, 115, 151, 220, // i=220 223, 112, 154, 221, // i=221 225, 109, 157, 222, // i=222 228, 106, 160, 223, // i=223 230, 103, 163, 224, // i=224 233, 100, 166, 225, // i=225 235, 97, 169, 226, // i=226 238, 94, 172, 227, // i=227 240, 91, 175, 228, // i=228 242, 88, 178, 229, // i=229 244, 85, 181, 230, // i=230 247, 82, 184, 231, // i=231 249, 79, 187, 232, // i=232 251, 76, 190, 233, // i=233 253, 73, 193, 234, // i=234 255, 70, 196, 235, // i=235 254, 67, 198, 236, // i=236 252, 64, 201, 237, // i=237 250, 61, 204, 238, // i=238 248, 58, 207, 239, // i=239 246, 55, 210, 240, // i=240 244, 53, 212, 241, // i=241 242, 50, 215, 242, // i=242 240, 47, 218, 243, // i=243 237, 44, 220, 244, // i=244 235, 41, 223, 245, // i=245 233, 39, 225, 246, // i=246 230, 36, 228, 247, // i=247 228, 33, 230, 248, // i=248 225, 31, 233, 249, // i=249 223, 28, 235, 250, // i=250 220, 26, 238, 251, // i=251 218, 23, 240, 252, // i=252 215, 21, 242, 253, // i=253 212, 18, 244, 254, // i=254 210, 16, 247, 255 // i=255 }; /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ uint16_t iter, cnt = 5; uint8_t init_retries = 5; uint8_t ralay_5v_on_var = 0; /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ float temperature; uint8_t roms[MAX_DEVICES][8]; Flags_TypeDef flag; //extern uint8_t devices_found ; uint8_t _debug_init = 0; TEMP_TypeDef temp_sense[30]; float set_temp_old[30]; char rx_buffer[64]; uint8_t rx_index = 0; char command_ready = 0; uint8_t uart_byte = 0; uint8_t first_in = 1; DALLAS_SensorHandleTypeDef sens[30]; int init_sens = 0; FlashRecord_t* record; uint8_t flash_buff[RECORD_SIZE - 4]; /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ int last_page_addr = LAST_PAGE_ADDR; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM1_Init(); MX_USART1_UART_Init(); MX_TIM2_Init(); MX_ADC1_Init(); MX_I2C1_Init(); MX_RTC_Init(); /* USER CODE BEGIN 2 */ led_blink(GPIOC, 13, rest_iter, reset_blink_delay); MODBUS_FirstInit(&hmodbus1, &mb_huart, &mb_htim); MODBUS_Config(&hmodbus1, MODBUS_DEVICE_ID, MODBUS_TIMEOUT, MODBUS_MODE_SLAVE); // Запуск приема Modbus MODBUS_SlaveStart(&hmodbus1, NULL); uint8_t uart_byte = 0; Dallas_BusFirstInit(&htim1); // ������������� �� ������� ��������� �������� // ������������� �� ������� (����������� ������ ���������� �������) reinit_t_sens(); init_setpoint_all_T_sense(temp_sense, hdallas.onewire->RomCnt); MB_DATA.InRegs.num_Tsens = hdallas.onewire->RomCnt; // BufferState_t buffer_state = buffer_init(); for(int i=0;iODR |= 1 << 13; // } // } temp_sense[0].t_close = 1; Field_modbus(&MB_DATA, &flag); Check_Tconnect(&MB_DATA, &flag, &hdallas, 0); value_control(); init_setpoint_all_T_sense(temp_sense, hdallas.onewire->RomCnt); // handle_valves(temp_sense[]); Dallas_StartConvertTAll(&hdallas, DALLAS_WAIT_BUS, 0); for(int i = 0; i < hdallas.onewire->RomCnt; i++) { if(sens[i].isLost) { sens[i].lost_cnt ++; } Dallas_ReadTemperature(&sens[i]); MB_DATA.InRegs.sens_Temp[i] = sens[i].temperature * 10; /////////////////////////заменить на define ralay_5v_on_var GPIOA->ODR|=1<<10; ralay_5v_on_var = MB_DATA.Coils.coils[1].state_val_bit.state_val_05; if (ralay_5v_on_var) { GPIOA->ODR |= 1 << 10; } else { GPIOA->ODR &= ~(1 << 10); } } /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ //iwdg_refresh(); //HAL_Delay(200); } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.LSIState = RCC_LSI_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_ADC; PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI; PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ void iwdg_refresh(void) { IWDG->KR = 0xAAAA; // �������� ������ } void led_blink(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint8_t iter, uint16_t delay) { for(int i = 0; i < iter; i++) { GPIOx->ODR ^= (1 << GPIO_Pin); HAL_Delay(delay); } } void Check_Tconnect(MB_DataStructureTypeDef* MB_DATA, Flags_TypeDef* flag, DALLAS_HandleTypeDef* hdallas, int a[0]) { for(int i = 0; i < hdallas->onewire->RomCnt; i++) { if(sens[i].isLost) { //init_sens=1; } } if (init_sens || flag->init_tsens) { init_sens = 0; flag->init_tsens = 0; //Dallas_BusFirstInit(&htim1); DS18B20_Search(&DS, &OW) ; reinit_t_sens(); MB_DATA->InRegs.num_Tsens = hdallas->onewire->RomCnt; } } void reinit_t_sens(void) { for ( int i = 0; i < hdallas.onewire->RomCnt; i++) { // ������������� �� ROM-������ //sens[i].Init.init_func = &Dallas_SensorInitByROM; // sens[i].Init.InitParam.ROM = rom_address; sens[i].Init.InitParam.Ind = i; sens[i].Init.init_func = &Dallas_SensorInitByInd; sens[i].Init.Resolution = DALLAS_CONFIG_9_BITS; MB_DATA.HoldRegs.set_Temp[i] = sens[i].set_temp = 20.; MB_DATA.HoldRegs.set_hyst[i] = sens[i].hyst = 1; Dallas_AddNewSensors(&hdallas, &sens[i]); } } FuncStat packStruct(MB_DataStructureTypeDef* MB_DATA, int sizeARR) { for(int i = 0; i < sizeARR; i++) { for(int sens_num = 0; sens_num < hdallas.onewire->RomCnt; sens_num++) { switch(sens_num) { case 0: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp1_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 1: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp2_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 2: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp3_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 3: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp4_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 4: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp5_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 5: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp6_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 6: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp7_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 7: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp8_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 8: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp9_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 9: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp10_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 10: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp11_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 11: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp12_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 12: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp13_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 13: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp14_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 14: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp15_isConnected = sens[i * 16 + sens_num ].isConnected; break; case 15: MB_DATA->Coils.status_tSens[i].state_val_bit.Temp16_isConnected = sens[i * 16 + sens_num ].isConnected; break; } } } return FuncOK; } FuncStat Field_modbus(MB_DataStructureTypeDef* MB_DATA, Flags_TypeDef* flag) { //MB_DATA->InRegs.reserve1 sin_table_phase_a MB_DATA->InRegs.ID = *hdallas.ds_devices; flag->init_tsens = MB_DATA->Coils.init_Tsens; packStruct(MB_DATA, MAX_SENSE / 16); if (_debug_init || MB_DATA->Coils.init_param) { _debug_init = 0; MB_DATA->Coils.init_param = 0; for(int i = 0; i < hdallas.onewire->RomCnt; i++) { sens[i].set_temp = MB_DATA->HoldRegs.set_Temp[i]; sens[i].hyst = MB_DATA->HoldRegs.set_hyst[i]; } } return FuncOK; }; FuncStat value_control(void ) { for(int i = 0; i < hdallas.onewire->RomCnt; i++) { if (sens[i].isLost==0) { sens[i].lost_cnt=0; if (sens[i].temperature < sens[i].set_temp - sens[i].hyst) { MB_DATA.Coils.relay_struct_off.all |= 1 << i; MB_DATA.Coils.relay_struct_on.all &= ~(1 << i); } else if (sens[i].temperature > sens[i].set_temp + sens[i].hyst) { MB_DATA.Coils.relay_struct_off.all &= ~(1 << i); MB_DATA.Coils.relay_struct_on.all |= 1 << i; } else if (sens[i].temperature == sens[i].set_temp ) { MB_DATA.Coils.relay_struct_on.all &= ~(1 << i); MB_DATA.Coils.relay_struct_off.all &= ~(1 << i); } } else { if(sens[i].lost_cnt>10) { MB_DATA.Coils.relay_struct_on.all &= ~(1 << i); MB_DATA.Coils.relay_struct_off.all &= ~(1 << i); } } } return FuncOK; } uint16_t handle_valves(TEMP_TypeDef* temp_sense[MAX_SENSE] ) { if (temp_sense[0]->state == STATE_OPEN_VALVE) { GPIOC->ODR |= 1 << 14; } else if (temp_sense[0]->state == STATE_CLOSE_VALVE) { GPIOC->ODR &= ~(1 << 14); } return 1; } void init_setpoint_all_T_sense(TEMP_TypeDef* temp_sense, int size_array) { //ds_search_devices(); for(int i = 0; i < size_array ; i++) { temp_sense[i].id[0] = roms[i][0] << 0 | roms[i][1] << 8 | roms[i][2] << 16 | roms[i][3] << 24; temp_sense[i].id[1] = roms[i][4] << 0 | roms[i][5] << 8 | roms[i][6] << 16 | roms[i][7] << 24; temp_sense[i].count = i + 1; temp_sense[i].location = 1; temp_sense[i].t_open = 22; temp_sense[i].t_close = 18; temp_sense[i].status_T_sense = 1; } } /* USER CODE END 4 */ /** * @brief Period elapsed callback in non blocking mode * @note This function is called when TIM3 interrupt took place, inside * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment * a global variable "uwTick" used as application time base. * @param htim : TIM handle * @retval None */ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { /* USER CODE BEGIN Callback 0 */ /* USER CODE END Callback 0 */ if (htim->Instance == TIM3) { HAL_IncTick(); } /* USER CODE BEGIN Callback 1 */ /* USER CODE END Callback 1 */ } /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */