Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b36ffe294c | |||
| 8552d8ee90 |
@@ -4,7 +4,7 @@
|
||||
//**********BEGIN defines***********
|
||||
//#define OldVer
|
||||
#define MAX_SENSE 32 // НЕ ДЕЛАТЬ МЕНЬШЕ 16
|
||||
#define project new_ver//old //new
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
53
john103C6T6/Core/Inc/dma.h
Normal file
53
john103C6T6/Core/Inc/dma.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file dma.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the dma.c file
|
||||
******************************************************************************
|
||||
* @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 */
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __DMA_H__
|
||||
#define __DMA_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* DMA memory to memory transfer handles -------------------------------------*/
|
||||
extern DMA_HandleTypeDef hdma_memtomem_dma1_channel1;
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_DMA_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DMA_H__ */
|
||||
|
||||
@@ -35,13 +35,12 @@ extern "C" {
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "modbus_data.h"
|
||||
#include "PROJ_setup.h"
|
||||
#include "dallas_tools.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "modbus_data.h"
|
||||
|
||||
#include "dallas_tools.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FuncOK=0,
|
||||
@@ -132,6 +131,8 @@ void Error_Handler(void);
|
||||
/* USER CODE END EFP */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define Relay_dc5v_Pin GPIO_PIN_10
|
||||
#define Relay_dc5v_GPIO_Port GPIOA
|
||||
#define One_wire_Pin GPIO_PIN_15
|
||||
#define One_wire_GPIO_Port GPIOA
|
||||
|
||||
|
||||
@@ -63,7 +63,6 @@ void TIM1_CC_IRQHandler(void);
|
||||
void TIM2_IRQHandler(void);
|
||||
void TIM3_IRQHandler(void);
|
||||
void USART1_IRQHandler(void);
|
||||
void USART2_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
@@ -34,14 +34,11 @@ extern "C" {
|
||||
|
||||
extern UART_HandleTypeDef huart1;
|
||||
|
||||
extern UART_HandleTypeDef huart2;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_USART1_UART_Init(void);
|
||||
void MX_USART2_UART_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
|
||||
67
john103C6T6/Core/Src/dma.c
Normal file
67
john103C6T6/Core/Src/dma.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file dma.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of all the requested memory to memory DMA transfers.
|
||||
******************************************************************************
|
||||
* @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 "dma.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Configure DMA */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
DMA_HandleTypeDef hdma_memtomem_dma1_channel1;
|
||||
|
||||
/**
|
||||
* Enable DMA controller clock
|
||||
* Configure DMA for memory to memory transfers
|
||||
* hdma_memtomem_dma1_channel1
|
||||
*/
|
||||
void MX_DMA_Init(void)
|
||||
{
|
||||
|
||||
/* DMA controller clock enable */
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
|
||||
/* Configure DMA request hdma_memtomem_dma1_channel1 on DMA1_Channel1 */
|
||||
hdma_memtomem_dma1_channel1.Instance = DMA1_Channel1;
|
||||
hdma_memtomem_dma1_channel1.Init.Direction = DMA_MEMORY_TO_MEMORY;
|
||||
hdma_memtomem_dma1_channel1.Init.PeriphInc = DMA_PINC_ENABLE;
|
||||
hdma_memtomem_dma1_channel1.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_memtomem_dma1_channel1.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_memtomem_dma1_channel1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
hdma_memtomem_dma1_channel1.Init.Mode = DMA_NORMAL;
|
||||
hdma_memtomem_dma1_channel1.Init.Priority = DMA_PRIORITY_LOW;
|
||||
if (HAL_DMA_Init(&hdma_memtomem_dma1_channel1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Configure GPIO */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -51,11 +52,13 @@ void MX_GPIO_Init(void)
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5
|
||||
|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|One_wire_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4
|
||||
|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8
|
||||
|GPIO_PIN_9|Relay_dc5v_Pin|One_wire_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_10
|
||||
@@ -63,16 +66,24 @@ void MX_GPIO_Init(void)
|
||||
|GPIO_PIN_15, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin : PC13 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_13;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PA0 PA1 PA4 PA5
|
||||
PA6 PA7 PA8 One_wire_Pin */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5
|
||||
|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|One_wire_Pin;
|
||||
/*Configure GPIO pin : PA0 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PA1 PA2 PA3 PA4
|
||||
PA5 PA6 PA7 PA8
|
||||
PA9 Relay_dc5v_Pin One_wire_Pin */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4
|
||||
|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8
|
||||
|GPIO_PIN_9|Relay_dc5v_Pin|One_wire_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
|
||||
@@ -27,10 +27,17 @@
|
||||
#include "usart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "dallas_tools.h"
|
||||
#include "PROJ_setup.h"
|
||||
|
||||
#include "def.h"
|
||||
#include <stdio.h>
|
||||
#include "modbus.h"
|
||||
@@ -54,7 +61,6 @@
|
||||
uint16_t iter, cnt = 5;
|
||||
uint8_t init_retries = 5;
|
||||
uint8_t ralay_5v_on_var = 0;
|
||||
uint16_t soft_reset=0;
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
@@ -104,39 +110,38 @@ void SystemClock_Config(void);
|
||||
int main(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
/* USER CODE BEGIN SysInit */
|
||||
|
||||
|
||||
/* USER CODE END 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_CAN_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_RTC_Init();
|
||||
MX_SPI1_Init();
|
||||
MX_USART2_UART_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_TIM1_Init();
|
||||
MX_USART1_UART_Init();
|
||||
MX_TIM2_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_CAN_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_RTC_Init();
|
||||
MX_SPI1_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
|
||||
|
||||
@@ -154,21 +159,19 @@ int main(void)
|
||||
|
||||
MB_DATA.InRegs.num_Tsens = hdallas.onewire->RomCnt;
|
||||
// BufferState_t buffer_state = buffer_init();
|
||||
for(int i=0;i<RECORD_SIZE;i++)
|
||||
{
|
||||
flash_buff[i]=i;
|
||||
|
||||
}
|
||||
/* USER CODE END 2 */
|
||||
for(int i=0;i<RECORD_SIZE;i++)
|
||||
{
|
||||
flash_buff[i]=i;
|
||||
|
||||
}
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
if (soft_reset)
|
||||
{
|
||||
HAL_NVIC_SystemReset();
|
||||
}
|
||||
|
||||
|
||||
// if (MB_DATA.Coils.relay_struct[0].state_val_bit.Temp11_relay_isOn)
|
||||
// {
|
||||
// MB_DATA.Coils.relay_struct[0].state_val_bit.Temp11_relay_isOn = 0;
|
||||
@@ -184,7 +187,7 @@ for(int i=0;i<RECORD_SIZE;i++)
|
||||
// new_record.timestamp = HAL_GetTick();
|
||||
// memcpy(new_record.data, flash_buff, sizeof(new_record.data));
|
||||
|
||||
// HAL_StatusTypeDef status = buffer_write_record(&new_record, &buffer_state);,
|
||||
// HAL_StatusTypeDef status = buffer_write_record(&new_record, &buffer_state);
|
||||
|
||||
// if (status == HAL_OK)
|
||||
// {
|
||||
@@ -225,14 +228,14 @@ for(int i=0;i<RECORD_SIZE;i++)
|
||||
|
||||
|
||||
|
||||
/* USER CODE END WHILE */
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
/* USER CODE BEGIN 3 */
|
||||
//iwdg_refresh();
|
||||
|
||||
//HAL_Delay(200);
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,46 +244,46 @@ for(int i=0;i<RECORD_SIZE;i++)
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
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 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;
|
||||
/** 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();
|
||||
}
|
||||
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 */
|
||||
@@ -505,16 +508,16 @@ void init_setpoint_all_T_sense(TEMP_TypeDef* temp_sense, int size_array)
|
||||
*/
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
/* USER CODE BEGIN Callback 0 */
|
||||
/* 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 0 */
|
||||
if (htim->Instance == TIM3)
|
||||
{
|
||||
HAL_IncTick();
|
||||
}
|
||||
/* USER CODE BEGIN Callback 1 */
|
||||
|
||||
/* USER CODE END Callback 1 */
|
||||
/* USER CODE END Callback 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -523,13 +526,13 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* 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 */
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
@@ -541,9 +544,9 @@ void Error_Handler(void)
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* 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 */
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
@@ -45,7 +45,7 @@ void MX_RTC_Init(void)
|
||||
*/
|
||||
hrtc.Instance = RTC;
|
||||
hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
|
||||
hrtc.Init.OutPut = RTC_OUTPUTSOURCE_SECOND;
|
||||
hrtc.Init.OutPut = RTC_OUTPUTSOURCE_NONE;
|
||||
if (HAL_RTC_Init(&hrtc) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
@@ -119,7 +119,7 @@ void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
|
||||
/* USER CODE BEGIN RTC_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END RTC_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
@@ -60,7 +60,6 @@ extern RTC_HandleTypeDef hrtc;
|
||||
extern TIM_HandleTypeDef htim1;
|
||||
extern TIM_HandleTypeDef htim2;
|
||||
extern UART_HandleTypeDef huart1;
|
||||
extern UART_HandleTypeDef huart2;
|
||||
extern TIM_HandleTypeDef htim3;
|
||||
|
||||
/* USER CODE BEGIN EV */
|
||||
@@ -315,7 +314,8 @@ static uint8_t first_in=1;
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN USART1_IRQn 0 */
|
||||
|
||||
RS_UART_Handler(&hmodbus1);
|
||||
return;
|
||||
/* USER CODE END USART1_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart1);
|
||||
/* USER CODE BEGIN USART1_IRQn 1 */
|
||||
@@ -325,21 +325,6 @@ void USART1_IRQHandler(void)
|
||||
/* USER CODE END USART1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USART2 global interrupt.
|
||||
*/
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN USART2_IRQn 0 */
|
||||
RS_UART_Handler(&hmodbus1);
|
||||
return;
|
||||
/* USER CODE END USART2_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart2);
|
||||
/* USER CODE BEGIN USART2_IRQn 1 */
|
||||
|
||||
/* USER CODE END USART2_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
@@ -83,7 +83,7 @@ void MX_TIM2_Init(void)
|
||||
|
||||
/* USER CODE END TIM2_Init 1 */
|
||||
htim2.Instance = TIM2;
|
||||
htim2.Init.Prescaler = 7199;
|
||||
htim2.Init.Prescaler = 72-1;
|
||||
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim2.Init.Period = 65535;
|
||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
/* USER CODE END 0 */
|
||||
|
||||
UART_HandleTypeDef huart1;
|
||||
UART_HandleTypeDef huart2;
|
||||
|
||||
/* USART1 init function */
|
||||
|
||||
@@ -55,35 +54,6 @@ void MX_USART1_UART_Init(void)
|
||||
|
||||
/* USER CODE END USART1_Init 2 */
|
||||
|
||||
}
|
||||
/* USART2 init function */
|
||||
|
||||
void MX_USART2_UART_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN USART2_Init 0 */
|
||||
|
||||
/* USER CODE END USART2_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN USART2_Init 1 */
|
||||
|
||||
/* USER CODE END USART2_Init 1 */
|
||||
huart2.Instance = USART2;
|
||||
huart2.Init.BaudRate = 115200;
|
||||
huart2.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart2.Init.StopBits = UART_STOPBITS_1;
|
||||
huart2.Init.Parity = UART_PARITY_NONE;
|
||||
huart2.Init.Mode = UART_MODE_TX_RX;
|
||||
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
if (HAL_UART_Init(&huart2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN USART2_Init 2 */
|
||||
|
||||
/* USER CODE END USART2_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
||||
@@ -98,20 +68,22 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
||||
/* USART1 clock enable */
|
||||
__HAL_RCC_USART1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**USART1 GPIO Configuration
|
||||
PA9 ------> USART1_TX
|
||||
PA10 ------> USART1_RX
|
||||
PB6 ------> USART1_TX
|
||||
PB7 ------> USART1_RX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_6;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_10;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
__HAL_AFIO_REMAP_USART1_ENABLE();
|
||||
|
||||
/* USART1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
|
||||
@@ -120,36 +92,6 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
||||
|
||||
/* USER CODE END USART1_MspInit 1 */
|
||||
}
|
||||
else if(uartHandle->Instance==USART2)
|
||||
{
|
||||
/* USER CODE BEGIN USART2_MspInit 0 */
|
||||
|
||||
/* USER CODE END USART2_MspInit 0 */
|
||||
/* USART2 clock enable */
|
||||
__HAL_RCC_USART2_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**USART2 GPIO Configuration
|
||||
PA2 ------> USART2_TX
|
||||
PA3 ------> USART2_RX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_3;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* USART2 interrupt Init */
|
||||
HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(USART2_IRQn);
|
||||
/* USER CODE BEGIN USART2_MspInit 1 */
|
||||
|
||||
/* USER CODE END USART2_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
|
||||
@@ -164,10 +106,10 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
|
||||
__HAL_RCC_USART1_CLK_DISABLE();
|
||||
|
||||
/**USART1 GPIO Configuration
|
||||
PA9 ------> USART1_TX
|
||||
PA10 ------> USART1_RX
|
||||
PB6 ------> USART1_TX
|
||||
PB7 ------> USART1_RX
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
|
||||
|
||||
/* USART1 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(USART1_IRQn);
|
||||
@@ -175,26 +117,6 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
|
||||
|
||||
/* USER CODE END USART1_MspDeInit 1 */
|
||||
}
|
||||
else if(uartHandle->Instance==USART2)
|
||||
{
|
||||
/* USER CODE BEGIN USART2_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END USART2_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_USART2_CLK_DISABLE();
|
||||
|
||||
/**USART2 GPIO Configuration
|
||||
PA2 ------> USART2_TX
|
||||
PA3 ------> USART2_RX
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
|
||||
|
||||
/* USART2 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(USART2_IRQn);
|
||||
/* USER CODE BEGIN USART2_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END USART2_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
127
john103C6T6/MDK-ARM/RTE/USB/USBD_Config_0.c
Normal file
127
john103C6T6/MDK-ARM/RTE/USB/USBD_Config_0.c
Normal file
@@ -0,0 +1,127 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
* MDK Middleware - Component ::USB:Device
|
||||
* Copyright (c) 2004-2023 Arm Limited (or its affiliates). All rights reserved.
|
||||
*------------------------------------------------------------------------------
|
||||
* Name: USBD_Config_0.c
|
||||
* Purpose: USB Device Configuration
|
||||
* Rev.: V5.3.0
|
||||
*------------------------------------------------------------------------------
|
||||
* Use the following configuration settings in the Device Class configuration
|
||||
* files to assign a Device Class to this USB Device 0.
|
||||
*
|
||||
* Configuration Setting Value
|
||||
* --------------------- -----
|
||||
* Assign Device Class to USB Device # = 0
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
|
||||
|
||||
// <h>USB Device 0
|
||||
// <o>Connect to hardware via Driver_USBD# <0-255>
|
||||
// <i>Select driver control block for hardware interface.
|
||||
#define USBD0_PORT 0
|
||||
|
||||
// <o.0>High-speed
|
||||
// <i>Enable High-speed functionality (if device supports it).
|
||||
#define USBD0_HS 0
|
||||
|
||||
// <h>Device Settings
|
||||
// <i>These settings are used to create the Device Descriptor
|
||||
// <o>Max Endpoint 0 Packet Size
|
||||
// <i>Maximum packet size for Endpoint 0 (bMaxPacketSize0).
|
||||
// <8=>8 Bytes <16=>16 Bytes <32=>32 Bytes <64=>64 Bytes
|
||||
#define USBD0_MAX_PACKET0 8
|
||||
|
||||
// <o.0..15>Vendor ID <0x0000-0xFFFF>
|
||||
// <i>Vendor ID assigned by USB-IF (idVendor).
|
||||
#define USBD0_DEV_DESC_IDVENDOR 0xC251
|
||||
|
||||
// <o.0..15>Product ID <0x0000-0xFFFF>
|
||||
// <i>Product ID assigned by manufacturer (idProduct).
|
||||
#define USBD0_DEV_DESC_IDPRODUCT 0x0000
|
||||
|
||||
// <o.0..15>Device Release Number <0x0000-0xFFFF>
|
||||
// <i>Device Release Number in binary-coded decimal (bcdDevice)
|
||||
#define USBD0_DEV_DESC_BCDDEVICE 0x0100
|
||||
|
||||
// </h>
|
||||
|
||||
// <h>Configuration Settings
|
||||
// <i>These settings are used to create the Configuration Descriptor.
|
||||
// <o.6>Power
|
||||
// <i>Default Power Setting (D6: of bmAttributes).
|
||||
// <0=>Bus-powered
|
||||
// <1=>Self-powered
|
||||
// <o.5>Remote Wakeup
|
||||
// <i>Configuration support for Remote Wakeup (D5: of bmAttributes).
|
||||
#define USBD0_CFG_DESC_BMATTRIBUTES 0x80
|
||||
|
||||
// <o.0..7>Maximum Power Consumption (in mA) <0-510><#/2>
|
||||
// <i>Maximum Power Consumption of USB Device from bus in this
|
||||
// <i>specific configuration when device is fully operational (bMaxPower).
|
||||
#define USBD0_CFG_DESC_BMAXPOWER 250
|
||||
|
||||
// </h>
|
||||
|
||||
// <h>String Settings
|
||||
// <i>These settings are used to create the String Descriptor.
|
||||
// <o.0..15>Language ID <0x0000-0xFCFF>
|
||||
// <i>English (United States) = 0x0409.
|
||||
#define USBD0_STR_DESC_LANGID 0x0409
|
||||
|
||||
// <s.126>Manufacturer String
|
||||
// <i>String Descriptor describing Manufacturer.
|
||||
#define USBD0_STR_DESC_MAN_RAW "Keil Software"
|
||||
|
||||
// <s.126>Product String
|
||||
// <i>String Descriptor describing Product.
|
||||
#define USBD0_STR_DESC_PROD_RAW "Keil USB Device 0"
|
||||
|
||||
// <e.0>Serial Number String
|
||||
// <i>Enable Serial Number String.
|
||||
// <i>If disabled Serial Number String will not be assigned to USB Device.
|
||||
#define USBD0_STR_DESC_SER_EN 1
|
||||
|
||||
// <s.126>Default value
|
||||
// <i>Default device's Serial Number String.
|
||||
#define USBD0_STR_DESC_SER_RAW "0001A0000000"
|
||||
|
||||
// <o.0..7>Maximum Length (in characters) <0-126>
|
||||
// <i>Specifies the maximum number of Serial Number String characters that can be set at run-time.
|
||||
// <i>Maximum value is 126. Use value 0 to disable RAM allocation for string.
|
||||
#define USBD0_STR_DESC_SER_MAX_LEN 16
|
||||
|
||||
// </e>
|
||||
// </h>
|
||||
|
||||
// <h>Microsoft OS Descriptors Settings
|
||||
// <i>These settings are used to create the Microsoft OS Descriptors.
|
||||
// <e.0>OS String
|
||||
// <i>Enable creation of Microsoft OS String and Extended Compat ID OS Feature Descriptors.
|
||||
#define USBD0_OS_DESC_EN 1
|
||||
|
||||
// <o.0..7>Vendor Code <0x01-0xFF>
|
||||
// <i>Specifies Vendor Code used to retrieve OS Feature Descriptors.
|
||||
#define USBD0_OS_DESC_VENDOR_CODE 0x01
|
||||
|
||||
// </e>
|
||||
// </h>
|
||||
|
||||
// <o>Control Transfer Buffer Size <64-65536:64>
|
||||
// <i>Specifies size of buffer used for Control Transfers.
|
||||
// <i>It should be at least as big as maximum packet size for Endpoint 0.
|
||||
#define USBD0_EP0_BUF_SIZE 128
|
||||
|
||||
// <h>OS Resources Settings
|
||||
// <i>These settings are used to optimize usage of OS resources.
|
||||
// <o>Core Thread Stack Size <64-65536>
|
||||
#define USBD0_CORE_THREAD_STACK_SIZE 512
|
||||
|
||||
// Core Thread Priority
|
||||
#define USBD0_CORE_THREAD_PRIORITY osPriorityAboveNormal
|
||||
|
||||
// </h>
|
||||
// </h>
|
||||
|
||||
|
||||
#include "usbd_config.h"
|
||||
127
john103C6T6/MDK-ARM/RTE/USB/USBD_Config_0.c.base@5.3.0
Normal file
127
john103C6T6/MDK-ARM/RTE/USB/USBD_Config_0.c.base@5.3.0
Normal file
@@ -0,0 +1,127 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
* MDK Middleware - Component ::USB:Device
|
||||
* Copyright (c) 2004-2023 Arm Limited (or its affiliates). All rights reserved.
|
||||
*------------------------------------------------------------------------------
|
||||
* Name: USBD_Config_0.c
|
||||
* Purpose: USB Device Configuration
|
||||
* Rev.: V5.3.0
|
||||
*------------------------------------------------------------------------------
|
||||
* Use the following configuration settings in the Device Class configuration
|
||||
* files to assign a Device Class to this USB Device 0.
|
||||
*
|
||||
* Configuration Setting Value
|
||||
* --------------------- -----
|
||||
* Assign Device Class to USB Device # = 0
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
|
||||
|
||||
// <h>USB Device 0
|
||||
// <o>Connect to hardware via Driver_USBD# <0-255>
|
||||
// <i>Select driver control block for hardware interface.
|
||||
#define USBD0_PORT 0
|
||||
|
||||
// <o.0>High-speed
|
||||
// <i>Enable High-speed functionality (if device supports it).
|
||||
#define USBD0_HS 0
|
||||
|
||||
// <h>Device Settings
|
||||
// <i>These settings are used to create the Device Descriptor
|
||||
// <o>Max Endpoint 0 Packet Size
|
||||
// <i>Maximum packet size for Endpoint 0 (bMaxPacketSize0).
|
||||
// <8=>8 Bytes <16=>16 Bytes <32=>32 Bytes <64=>64 Bytes
|
||||
#define USBD0_MAX_PACKET0 8
|
||||
|
||||
// <o.0..15>Vendor ID <0x0000-0xFFFF>
|
||||
// <i>Vendor ID assigned by USB-IF (idVendor).
|
||||
#define USBD0_DEV_DESC_IDVENDOR 0xC251
|
||||
|
||||
// <o.0..15>Product ID <0x0000-0xFFFF>
|
||||
// <i>Product ID assigned by manufacturer (idProduct).
|
||||
#define USBD0_DEV_DESC_IDPRODUCT 0x0000
|
||||
|
||||
// <o.0..15>Device Release Number <0x0000-0xFFFF>
|
||||
// <i>Device Release Number in binary-coded decimal (bcdDevice)
|
||||
#define USBD0_DEV_DESC_BCDDEVICE 0x0100
|
||||
|
||||
// </h>
|
||||
|
||||
// <h>Configuration Settings
|
||||
// <i>These settings are used to create the Configuration Descriptor.
|
||||
// <o.6>Power
|
||||
// <i>Default Power Setting (D6: of bmAttributes).
|
||||
// <0=>Bus-powered
|
||||
// <1=>Self-powered
|
||||
// <o.5>Remote Wakeup
|
||||
// <i>Configuration support for Remote Wakeup (D5: of bmAttributes).
|
||||
#define USBD0_CFG_DESC_BMATTRIBUTES 0x80
|
||||
|
||||
// <o.0..7>Maximum Power Consumption (in mA) <0-510><#/2>
|
||||
// <i>Maximum Power Consumption of USB Device from bus in this
|
||||
// <i>specific configuration when device is fully operational (bMaxPower).
|
||||
#define USBD0_CFG_DESC_BMAXPOWER 250
|
||||
|
||||
// </h>
|
||||
|
||||
// <h>String Settings
|
||||
// <i>These settings are used to create the String Descriptor.
|
||||
// <o.0..15>Language ID <0x0000-0xFCFF>
|
||||
// <i>English (United States) = 0x0409.
|
||||
#define USBD0_STR_DESC_LANGID 0x0409
|
||||
|
||||
// <s.126>Manufacturer String
|
||||
// <i>String Descriptor describing Manufacturer.
|
||||
#define USBD0_STR_DESC_MAN_RAW "Keil Software"
|
||||
|
||||
// <s.126>Product String
|
||||
// <i>String Descriptor describing Product.
|
||||
#define USBD0_STR_DESC_PROD_RAW "Keil USB Device 0"
|
||||
|
||||
// <e.0>Serial Number String
|
||||
// <i>Enable Serial Number String.
|
||||
// <i>If disabled Serial Number String will not be assigned to USB Device.
|
||||
#define USBD0_STR_DESC_SER_EN 1
|
||||
|
||||
// <s.126>Default value
|
||||
// <i>Default device's Serial Number String.
|
||||
#define USBD0_STR_DESC_SER_RAW "0001A0000000"
|
||||
|
||||
// <o.0..7>Maximum Length (in characters) <0-126>
|
||||
// <i>Specifies the maximum number of Serial Number String characters that can be set at run-time.
|
||||
// <i>Maximum value is 126. Use value 0 to disable RAM allocation for string.
|
||||
#define USBD0_STR_DESC_SER_MAX_LEN 16
|
||||
|
||||
// </e>
|
||||
// </h>
|
||||
|
||||
// <h>Microsoft OS Descriptors Settings
|
||||
// <i>These settings are used to create the Microsoft OS Descriptors.
|
||||
// <e.0>OS String
|
||||
// <i>Enable creation of Microsoft OS String and Extended Compat ID OS Feature Descriptors.
|
||||
#define USBD0_OS_DESC_EN 1
|
||||
|
||||
// <o.0..7>Vendor Code <0x01-0xFF>
|
||||
// <i>Specifies Vendor Code used to retrieve OS Feature Descriptors.
|
||||
#define USBD0_OS_DESC_VENDOR_CODE 0x01
|
||||
|
||||
// </e>
|
||||
// </h>
|
||||
|
||||
// <o>Control Transfer Buffer Size <64-65536:64>
|
||||
// <i>Specifies size of buffer used for Control Transfers.
|
||||
// <i>It should be at least as big as maximum packet size for Endpoint 0.
|
||||
#define USBD0_EP0_BUF_SIZE 128
|
||||
|
||||
// <h>OS Resources Settings
|
||||
// <i>These settings are used to optimize usage of OS resources.
|
||||
// <o>Core Thread Stack Size <64-65536>
|
||||
#define USBD0_CORE_THREAD_STACK_SIZE 512
|
||||
|
||||
// Core Thread Priority
|
||||
#define USBD0_CORE_THREAD_PRIORITY osPriorityAboveNormal
|
||||
|
||||
// </h>
|
||||
// </h>
|
||||
|
||||
|
||||
#include "usbd_config.h"
|
||||
@@ -45,7 +45,7 @@
|
||||
<PageWidth>79</PageWidth>
|
||||
<PageLength>66</PageLength>
|
||||
<TabStop>8</TabStop>
|
||||
<ListingPath>.\john103C6T6\</ListingPath>
|
||||
<ListingPath>C:\Users\z\Documents\</ListingPath>
|
||||
</OPTLEX>
|
||||
<ListingPage>
|
||||
<CreateCListing>1</CreateCListing>
|
||||
@@ -125,7 +125,7 @@
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>ST-LINKIII-KEIL_SWO</Key>
|
||||
<Name>-U37FF71064E57343634C31443 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM) -WA0 -WE0 -WVCE4 -WS2710 -WM0 -WP2 -WK0-R0</Name>
|
||||
<Name>-U7&2A27EDAB&0&3 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM) -WA0 -WE0 -WVCE4 -WS2710 -WM0 -WP2 -WK0-R0</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
@@ -153,43 +153,73 @@
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>state</ItemText>
|
||||
<ItemText>sens,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>1</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>last_page_addr</ItemText>
|
||||
<ItemText>MB_DATA,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>2</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>\\john103C6T6\../EEPROM_Emul/src/flash_ring.c\buffer_write_record\record_addr</ItemText>
|
||||
<ItemText>temp_sense</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>3</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>record</ItemText>
|
||||
<ItemText>roms</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>4</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>new_record</ItemText>
|
||||
<ItemText>state</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>5</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>state</ItemText>
|
||||
<ItemText>last_page_addr</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>6</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>htim</ItemText>
|
||||
<ItemText>\\john103C6T6\../EEPROM_Emul/src/flash_ring.c\buffer_write_record\record_addr</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>7</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>record</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>8</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>flash_buff</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>9</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>new_record</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>10</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>state</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>11</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>htim</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>12</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>sens[i].set_temp</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>13</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>flag,0x0A</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<WatchWindow2>
|
||||
<Ww>
|
||||
@@ -197,6 +227,16 @@
|
||||
<WinNumber>2</WinNumber>
|
||||
<ItemText>resolution</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>1</count>
|
||||
<WinNumber>2</WinNumber>
|
||||
<ItemText>hmodbus1</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>2</count>
|
||||
<WinNumber>2</WinNumber>
|
||||
<ItemText>hdallas,0x0A</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow2>
|
||||
<MemoryWindow1>
|
||||
<Mm>
|
||||
@@ -253,10 +293,6 @@
|
||||
<Name>System Viewer\FLASH</Name>
|
||||
<WinId>35904</WinId>
|
||||
</Entry>
|
||||
<Entry>
|
||||
<Name>System Viewer\GPIOA</Name>
|
||||
<WinId>35903</WinId>
|
||||
</Entry>
|
||||
<Entry>
|
||||
<Name>System Viewer\GPIOB</Name>
|
||||
<WinId>35900</WinId>
|
||||
@@ -354,18 +390,6 @@
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>6</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\EEPROM_Emul\src\flash_ring.c</PathWithFileName>
|
||||
<FilenameWithoutPath>flash_ring.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>7</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
@@ -376,7 +400,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>8</FileNumber>
|
||||
<FileNumber>7</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -388,7 +412,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>9</FileNumber>
|
||||
<FileNumber>8</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -400,7 +424,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>10</FileNumber>
|
||||
<FileNumber>9</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -412,7 +436,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>11</FileNumber>
|
||||
<FileNumber>10</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -424,7 +448,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>12</FileNumber>
|
||||
<FileNumber>11</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -436,7 +460,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>13</FileNumber>
|
||||
<FileNumber>12</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -448,7 +472,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>14</FileNumber>
|
||||
<FileNumber>13</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -460,7 +484,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>15</FileNumber>
|
||||
<FileNumber>14</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -472,7 +496,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>16</FileNumber>
|
||||
<FileNumber>15</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -484,7 +508,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>17</FileNumber>
|
||||
<FileNumber>16</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -496,7 +520,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>18</FileNumber>
|
||||
<FileNumber>17</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -506,11 +530,23 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>18</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\EEPROM_Emul\src\flash_ring.c</PathWithFileName>
|
||||
<FilenameWithoutPath>flash_ring.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
<GroupName>Drivers/STM32F1xx_HAL_Driver</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
@@ -960,6 +996,14 @@
|
||||
<RteFlg>1</RteFlg>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
<GroupName>::CMSIS Driver</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>1</RteFlg>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
<GroupName>::Compiler</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
<CreateHexFile>1</CreateHexFile>
|
||||
<DebugInformation>1</DebugInformation>
|
||||
<BrowseInformation>1</BrowseInformation>
|
||||
<ListingPath>.\john103C6T6\</ListingPath>
|
||||
<ListingPath>C:\Users\z\Documents\</ListingPath>
|
||||
<HexFormatSelection>1</HexFormatSelection>
|
||||
<Merge32K>0</Merge32K>
|
||||
<CreateBatchFile>0</CreateBatchFile>
|
||||
@@ -82,7 +82,7 @@
|
||||
</BeforeMake>
|
||||
<AfterMake>
|
||||
<RunUserProg1>0</RunUserProg1>
|
||||
<RunUserProg2>1</RunUserProg2>
|
||||
<RunUserProg2>0</RunUserProg2>
|
||||
<UserProg1Name></UserProg1Name>
|
||||
<UserProg2Name></UserProg2Name>
|
||||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
||||
@@ -341,7 +341,7 @@
|
||||
<MiscControls></MiscControls>
|
||||
<Define>USE_HAL_DRIVER,STM32F103xB</Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>../Core/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include;../Modbus;../EEPROM_Emul/lib;../../core/STM32_Modbus/Inc</IncludePath>
|
||||
<IncludePath>../Core/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include;../Modbus;..\EEPROM_Emul\lib;..\..\core\STM32_Modbus\Inc;..\EEPROM_Emul\lib</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
@@ -415,11 +415,6 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Core\Src\ow_port.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>flash_ring.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\EEPROM_Emul\src\flash_ring.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>main.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
@@ -735,6 +730,11 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>../Core/Src/stm32f1xx_hal_timebase_tim.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>flash_ring.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\EEPROM_Emul\src\flash_ring.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
@@ -1287,6 +1287,9 @@
|
||||
<Group>
|
||||
<GroupName>::CMSIS</GroupName>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>::CMSIS Driver</GroupName>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>::Compiler</GroupName>
|
||||
</Group>
|
||||
@@ -1295,8 +1298,21 @@
|
||||
</Targets>
|
||||
|
||||
<RTE>
|
||||
<apis/>
|
||||
<apis>
|
||||
<api Capiversion="2.3.0" Cclass="CMSIS Driver" Cgroup="Flash" exclusive="0">
|
||||
<package name="CMSIS" schemaVersion="1.7.7" url="http://www.keil.com/pack/" vendor="ARM" version="5.9.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="john103C6T6"/>
|
||||
</targetInfos>
|
||||
</api>
|
||||
</apis>
|
||||
<components>
|
||||
<component Capiversion="2.3.0" Cclass="CMSIS Driver" Cgroup="Flash" Csub="Custom" Cvendor="ARM" Cversion="1.0.0" custom="1">
|
||||
<package name="CMSIS" schemaVersion="1.7.7" url="http://www.keil.com/pack/" vendor="ARM" version="5.9.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="john103C6T6"/>
|
||||
</targetInfos>
|
||||
</component>
|
||||
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="6.1.0" condition="ARMv6_7_8-M Device">
|
||||
<package name="CMSIS" schemaVersion="1.7.36" url="https://www.keil.com/pack/" vendor="ARM" version="6.1.0"/>
|
||||
<targetInfos>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef _MODBUS_CONFIG_H_
|
||||
#define _MODBUS_CONFIG_H_
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "PROJ_setup.h"
|
||||
|
||||
// Общие параметры
|
||||
#define MODBUS_DEVICE_ID 3 ///< Адрес устройства в сети Modbus
|
||||
#define MODBUS_TIMEOUT 5000 ///< Таймаут в тиках таймера
|
||||
@@ -38,12 +38,7 @@
|
||||
#define MODBUS_USEROBJECT_0_NAME "" ///< Строка пользовательского идентификатора 0. По аналогии можно определить строки до <=128 USEROBJECT
|
||||
|
||||
// Периферия (опционально)
|
||||
#if (project == new_ver)
|
||||
#define mb_huart huart2
|
||||
#elif (project== old_ver)
|
||||
#define mb_huart huart1
|
||||
#endif
|
||||
///< Удобный дефайн для модбасовского uart
|
||||
#define mb_huart huart1 ///< Удобный дефайн для модбасовского uart
|
||||
#define mb_htim htim2 ///< Удобный дефайн для модбасовского таймера
|
||||
//#define RS_EnableReceive() ///< Функция изменения направления передачи на ПРИЕМ для RS-485
|
||||
//#define RS_EnableTransmit() ///< Функция изменения направления передачи на ПЕРЕДАЧУ для RS-485
|
||||
|
||||
@@ -21,7 +21,6 @@ Mcu.Family=STM32F1
|
||||
Mcu.IP0=ADC1
|
||||
Mcu.IP1=CAN
|
||||
Mcu.IP10=USART1
|
||||
Mcu.IP11=USART2
|
||||
Mcu.IP2=I2C1
|
||||
Mcu.IP3=NVIC
|
||||
Mcu.IP4=RCC
|
||||
@@ -30,7 +29,7 @@ Mcu.IP6=SPI1
|
||||
Mcu.IP7=SYS
|
||||
Mcu.IP8=TIM1
|
||||
Mcu.IP9=TIM2
|
||||
Mcu.IPNb=12
|
||||
Mcu.IPNb=11
|
||||
Mcu.Name=STM32F103C(4-6)Tx
|
||||
Mcu.Package=LQFP48
|
||||
Mcu.Pin0=PC13-TAMPER-RTC
|
||||
@@ -58,22 +57,24 @@ Mcu.Pin28=PB3
|
||||
Mcu.Pin29=PB4
|
||||
Mcu.Pin3=PA0-WKUP
|
||||
Mcu.Pin30=PB5
|
||||
Mcu.Pin31=PB8
|
||||
Mcu.Pin32=PB9
|
||||
Mcu.Pin33=VP_ADC1_TempSens_Input
|
||||
Mcu.Pin34=VP_ADC1_Vref_Input
|
||||
Mcu.Pin35=VP_RTC_VS_RTC_Activate
|
||||
Mcu.Pin36=VP_RTC_VS_RTC_Calendar
|
||||
Mcu.Pin37=VP_SYS_VS_tim3
|
||||
Mcu.Pin38=VP_TIM1_VS_ClockSourceINT
|
||||
Mcu.Pin39=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin31=PB6
|
||||
Mcu.Pin32=PB7
|
||||
Mcu.Pin33=PB8
|
||||
Mcu.Pin34=PB9
|
||||
Mcu.Pin35=VP_ADC1_TempSens_Input
|
||||
Mcu.Pin36=VP_ADC1_Vref_Input
|
||||
Mcu.Pin37=VP_RTC_VS_RTC_Activate
|
||||
Mcu.Pin38=VP_RTC_VS_RTC_Calendar
|
||||
Mcu.Pin39=VP_SYS_VS_tim3
|
||||
Mcu.Pin4=PA1
|
||||
Mcu.Pin40=VP_TIM1_VS_ClockSourceINT
|
||||
Mcu.Pin41=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin5=PA2
|
||||
Mcu.Pin6=PA3
|
||||
Mcu.Pin7=PA4
|
||||
Mcu.Pin8=PA5
|
||||
Mcu.Pin9=PA6
|
||||
Mcu.PinsNb=40
|
||||
Mcu.PinsNb=42
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32F103C6Tx
|
||||
@@ -99,15 +100,15 @@ NVIC.TIM3_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:true
|
||||
NVIC.TimeBase=TIM3_IRQn
|
||||
NVIC.TimeBaseIP=TIM3
|
||||
NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
NVIC.USART2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
PA0-WKUP.Locked=true
|
||||
PA0-WKUP.Signal=GPIO_Output
|
||||
PA0-WKUP.Signal=GPIO_Input
|
||||
PA1.Locked=true
|
||||
PA1.Signal=GPIO_Output
|
||||
PA10.GPIOParameters=GPIO_Label
|
||||
PA10.GPIO_Label=Relay_dc5v
|
||||
PA10.Locked=true
|
||||
PA10.Mode=Asynchronous
|
||||
PA10.Signal=USART1_RX
|
||||
PA10.Signal=GPIO_Output
|
||||
PA11.Mode=CAN_Activate
|
||||
PA11.Signal=CAN_RX
|
||||
PA12.Mode=CAN_Activate
|
||||
@@ -120,10 +121,10 @@ PA15.GPIOParameters=GPIO_Label
|
||||
PA15.GPIO_Label=One_wire
|
||||
PA15.Locked=true
|
||||
PA15.Signal=GPIO_Output
|
||||
PA2.Mode=Asynchronous
|
||||
PA2.Signal=USART2_TX
|
||||
PA3.Mode=Asynchronous
|
||||
PA3.Signal=USART2_RX
|
||||
PA2.Locked=true
|
||||
PA2.Signal=GPIO_Output
|
||||
PA3.Locked=true
|
||||
PA3.Signal=GPIO_Output
|
||||
PA4.Locked=true
|
||||
PA4.Signal=GPIO_Output
|
||||
PA5.Locked=true
|
||||
@@ -135,8 +136,7 @@ PA7.Signal=GPIO_Output
|
||||
PA8.Locked=true
|
||||
PA8.Signal=GPIO_Output
|
||||
PA9.Locked=true
|
||||
PA9.Mode=Asynchronous
|
||||
PA9.Signal=USART1_TX
|
||||
PA9.Signal=GPIO_Output
|
||||
PB0.Locked=true
|
||||
PB0.Signal=GPIO_Output
|
||||
PB1.Locked=true
|
||||
@@ -161,6 +161,10 @@ PB4.Mode=Full_Duplex_Master
|
||||
PB4.Signal=SPI1_MISO
|
||||
PB5.Mode=Full_Duplex_Master
|
||||
PB5.Signal=SPI1_MOSI
|
||||
PB6.Mode=Asynchronous
|
||||
PB6.Signal=USART1_TX
|
||||
PB7.Mode=Asynchronous
|
||||
PB7.Signal=USART1_RX
|
||||
PB8.Mode=I2C
|
||||
PB8.Signal=I2C1_SCL
|
||||
PB9.Mode=I2C
|
||||
@@ -188,7 +192,7 @@ ProjectManager.HalAssertFull=false
|
||||
ProjectManager.HeapSize=0x400
|
||||
ProjectManager.KeepUserCode=true
|
||||
ProjectManager.LastFirmware=true
|
||||
ProjectManager.LibraryCopy=0
|
||||
ProjectManager.LibraryCopy=1
|
||||
ProjectManager.MainLocation=Core/Src
|
||||
ProjectManager.NoMain=false
|
||||
ProjectManager.PreviousToolchain=
|
||||
@@ -203,7 +207,7 @@ ProjectManager.ToolChainLocation=
|
||||
ProjectManager.UAScriptAfterPath=
|
||||
ProjectManager.UAScriptBeforePath=
|
||||
ProjectManager.UnderRoot=false
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_TIM1_Init-TIM1-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_TIM2_Init-TIM2-false-HAL-true,6-MX_ADC1_Init-ADC1-false-HAL-true,7-MX_CAN_Init-CAN-false-HAL-true,8-MX_I2C1_Init-I2C1-false-HAL-true,9-MX_RTC_Init-RTC-false-HAL-true,10-MX_SPI1_Init-SPI1-false-HAL-true,11-MX_USART2_UART_Init-USART2-false-HAL-true
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_TIM1_Init-TIM1-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_TIM2_Init-TIM2-false-HAL-true,6-MX_ADC1_Init-ADC1-false-HAL-true,7-MX_CAN_Init-CAN-false-HAL-true,8-MX_I2C1_Init-I2C1-false-HAL-true,9-MX_RTC_Init-RTC-false-HAL-true,10-MX_SPI1_Init-SPI1-false-HAL-true
|
||||
RCC.ADCFreqValue=12000000
|
||||
RCC.ADCPresc=RCC_ADCPCLK2_DIV6
|
||||
RCC.AHBFreq_Value=72000000
|
||||
@@ -243,8 +247,6 @@ TIM2.Period=65535
|
||||
TIM2.Prescaler=7199
|
||||
USART1.IPParameters=VirtualMode
|
||||
USART1.VirtualMode=VM_ASYNC
|
||||
USART2.IPParameters=VirtualMode
|
||||
USART2.VirtualMode=VM_ASYNC
|
||||
VP_ADC1_TempSens_Input.Mode=IN-TempSens
|
||||
VP_ADC1_TempSens_Input.Signal=ADC1_TempSens_Input
|
||||
VP_ADC1_Vref_Input.Mode=IN-Vrefint
|
||||
|
||||
38
john103C6T6NewVer/.mxproject
Normal file
38
john103C6T6NewVer/.mxproject
Normal file
File diff suppressed because one or more lines are too long
13
john103C6T6NewVer/Core/Inc/Proj_setup.h
Normal file
13
john103C6T6NewVer/Core/Inc/Proj_setup.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef __PROJ_SETUP
|
||||
#define __PROJ_SETUP
|
||||
|
||||
//**********BEGIN defines***********
|
||||
//#define OldVer
|
||||
#define MAX_SENSE 32 // НЕ ДЕЛАТЬ МЕНЬШЕ 16
|
||||
|
||||
|
||||
|
||||
|
||||
//**********END defines***********
|
||||
|
||||
#endif
|
||||
52
john103C6T6NewVer/Core/Inc/adc.h
Normal file
52
john103C6T6NewVer/Core/Inc/adc.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file adc.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the adc.c file
|
||||
******************************************************************************
|
||||
* @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 */
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __ADC_H__
|
||||
#define __ADC_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_ADC1_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ADC_H__ */
|
||||
|
||||
170
john103C6T6NewVer/Core/Inc/dallas_tools.h
Normal file
170
john103C6T6NewVer/Core/Inc/dallas_tools.h
Normal file
@@ -0,0 +1,170 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file dallas_tools.h
|
||||
* @brief Драйвер датчиков температуры DALLAS
|
||||
******************************************************************************
|
||||
* Этот файл предоставляет объявления и определения для работы с датчиками
|
||||
* температуры DS18B20. Он включает структуры данных, макросы и прототипы
|
||||
* функций для инициализации, чтения температуры
|
||||
* и управления датчиками.
|
||||
*
|
||||
* Работа с датчиками ведётся через протокол OneWire.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DALLAS_TOOLS_H
|
||||
#define DALLAS_TOOLS_H
|
||||
|
||||
/* Includes -----------------------------------------------------------------*/
|
||||
#include "ds18b20_driver.h"
|
||||
#include "onewire.h"
|
||||
|
||||
|
||||
/* Определения пользовательских байтов для записи чтения */
|
||||
#define DALLAS_USER_BYTE_1 (1<<0) ///< Первый пользовательский байт
|
||||
#define DALLAS_USER_BYTE_2 (1<<1) ///< Второй пользовательский байт
|
||||
#define DALLAS_USER_BYTE_3 (1<<2) ///< Третий пользовательский байт
|
||||
#define DALLAS_USER_BYTE_4 (1<<3) ///< Четвёртый пользовательский байт
|
||||
|
||||
#define DALLAS_USER_BYTE_12 (DALLAS_USER_BYTE_1|DALLAS_USER_BYTE_2) ///< Первые два байта
|
||||
#define DALLAS_USER_BYTE_34 (DALLAS_USER_BYTE_3|DALLAS_USER_BYTE_4) ///< Вторые два байта
|
||||
#define DALLAS_USER_BYTE_ALL (DALLAS_USER_BYTE_12|DALLAS_USER_BYTE_34) ///< Все пользовательские байты
|
||||
|
||||
/* Declarations and definitions ---------------------------------------------*/
|
||||
#define DALLAS_ROM_SIZE 8
|
||||
|
||||
#define DALLAS_CONFIG_9_BITS 0x1F
|
||||
#define DALLAS_CONFIG_10_BITS 0x3F
|
||||
#define DALLAS_CONFIG_11_BITS 0x5F
|
||||
#define DALLAS_CONFIG_12_BITS 0x7F
|
||||
|
||||
#define DALLAS_DELAY_MS_9_BITS 94
|
||||
#define DALLAS_DELAY_MS_10_BITS 188
|
||||
#define DALLAS_DELAY_MS_11_BITS 375
|
||||
#define DALLAS_DELAY_MS_12_BITS 750
|
||||
#define DALLAS_DELAY_MS_MAX DALLAS_DELAY_MS_12_BITS
|
||||
|
||||
typedef struct _SensorHandleStruct DALLAS_SensorHandleTypeDef;
|
||||
typedef struct _DallasHandleStruct DALLAS_HandleTypeDef;
|
||||
|
||||
/** @brief Структура Scratchpad датчика DALLAS */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t TemperatureLSB; ///< Младший байт температуры
|
||||
uint8_t TemperatureMSB; ///< Старший байт температуры
|
||||
uint8_t tHighRegister; ///< Верхний температурный порог
|
||||
uint8_t tLowRegister; ///< Нижний температурный порог
|
||||
uint8_t ConfigRegister; ///< Конфигурационный регистр
|
||||
uint8_t reserved; ///< Зарезервировано
|
||||
uint8_t UserByte3; ///< Пользовательский байт 3
|
||||
uint8_t UserByte4; ///< Пользовательский байт 4
|
||||
uint8_t ScratchpadCRC; ///< Контрольная сумма
|
||||
}DALLAS_ScratchpadTypeDef;
|
||||
|
||||
/** @brief Структура флагов ошибок датчиков DALLAS */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t disconnect_cnt; ///< Счетчик отключений датчика
|
||||
uint8_t read_temperature_err_cnt; ///< Счетчик ошибок чтения температуры
|
||||
uint8_t timeout_convertion_cnt; ///< Счетчик ошибок таймаута конвертации
|
||||
uint8_t write_err_cnt; ///< Счетчик других ошибок
|
||||
}DALLAS_FlagsTypeDef;
|
||||
|
||||
|
||||
/** @brief Структура инициализации датчика DALLAS */
|
||||
typedef struct __packed
|
||||
{
|
||||
union
|
||||
{
|
||||
uint64_t Ind; ///< порядковый номер датчика
|
||||
uint64_t ROM; ///< ROM датчика
|
||||
struct
|
||||
{
|
||||
uint8_t UserByte1; ///< Младший байт (бит 0–7)
|
||||
uint8_t UserByte2; ///< Следующий байт (бит 8–15)
|
||||
uint8_t UserByte3; ///< Байт (бит 16–23)
|
||||
uint8_t UserByte4; ///< Байт (бит 24–31)
|
||||
uint8_t Reserved[4]; ///< Остальные байты (бит 32–63, если нужно)
|
||||
} UserBytes; ///< UserBytes датчика
|
||||
}InitParam; ///< Параметр для инициализации: ROM/UserBytes/Индекс
|
||||
uint8_t Resolution; ///< Разрешение датчика
|
||||
HAL_StatusTypeDef (*init_func)(DALLAS_HandleTypeDef *, DALLAS_SensorHandleTypeDef *); ///< Функция инициализации
|
||||
} DALLAS_InitStructTypeDef;
|
||||
|
||||
|
||||
|
||||
/** @brief Cтруктура обработчика DALLAS для общения с датчиком*/
|
||||
struct _DallasHandleStruct
|
||||
{
|
||||
OneWire_t *onewire;
|
||||
DS18B20_Drv_t *ds_devices;
|
||||
DALLAS_ScratchpadTypeDef scratchpad;
|
||||
};
|
||||
extern DALLAS_HandleTypeDef hdallas;
|
||||
|
||||
/** @brief Основная структура обработчика датчика DALLAS */
|
||||
struct _SensorHandleStruct
|
||||
{
|
||||
unsigned isConnected:1; ///< Флаг соединения
|
||||
unsigned isInitialized:1; ///< Флаг инициализации
|
||||
unsigned isLost:1; ///< Флаг потери связи
|
||||
uint16_t lost_cnt;
|
||||
DALLAS_FlagsTypeDef f; ///< Флаги
|
||||
|
||||
|
||||
float set_temp;
|
||||
uint16_t hyst;
|
||||
|
||||
DALLAS_HandleTypeDef *hdallas;
|
||||
uint64_t sensROM; ///< ROM-код датчика
|
||||
|
||||
float temperature; ///< Текущая температура
|
||||
|
||||
DALLAS_InitStructTypeDef Init; ///< Структура инициализации
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** @brief Варианты ожидания окончания конверсии */
|
||||
typedef enum
|
||||
{
|
||||
DALLAS_WAIT_NONE = 0x00, ///< Без ожидания окончания конверсии
|
||||
DALLAS_WAIT_BUS = 0x01, ///< Ожидание окончания конверсии по шине (опрос датчиков - чтение бита)
|
||||
DALLAS_WAIT_DELAY = 0x02, ///< Без ожидания окончания через задержку (максимальная задержка для заданной разрядности)
|
||||
} DALLAS_WaitConvertionTypeDef;
|
||||
|
||||
|
||||
|
||||
/* Functions ---------------------------------------------------------------*/
|
||||
|
||||
HAL_StatusTypeDef Dallas_BusFirstInit(TIM_HandleTypeDef *htim);
|
||||
/* Функция для иниицализации нового датчика в структуре */
|
||||
HAL_StatusTypeDef Dallas_AddNewSensors(DALLAS_HandleTypeDef *hdallas, DALLAS_SensorHandleTypeDef *sensor);
|
||||
/* Инициализирует структуру датчика по ROM */
|
||||
HAL_StatusTypeDef Dallas_SensorInitByROM(DALLAS_HandleTypeDef *hdallas, DALLAS_SensorHandleTypeDef *sensor);
|
||||
/* Инициализирует структуру датчика по пользовательским байтам */
|
||||
HAL_StatusTypeDef Dallas_SensorInitByUserBytes(DALLAS_HandleTypeDef *hdallas, DALLAS_SensorHandleTypeDef *sensor);
|
||||
/* Инициализирует структуру датчика по порядковому номеру */
|
||||
HAL_StatusTypeDef Dallas_SensorInitByInd(DALLAS_HandleTypeDef *hdallas, DALLAS_SensorHandleTypeDef *sensor);
|
||||
/* Инициализирует датчик для работы */
|
||||
HAL_StatusTypeDef Dallas_SensorInit(DALLAS_HandleTypeDef *hdallas, DALLAS_SensorHandleTypeDef *sensor, uint8_t (*ROM)[DALLAS_ROM_SIZE]);
|
||||
/* Деинициализирует структуру датчика */
|
||||
HAL_StatusTypeDef Dallas_SensorDeInit(DALLAS_SensorHandleTypeDef *sensor);
|
||||
/* Функция для нахождения нового датчика на место потерянного */
|
||||
HAL_StatusTypeDef Dallas_ReplaceLostedSensor(DALLAS_SensorHandleTypeDef *sensor);
|
||||
/* Запускает измерение температуры на всех датчиках */
|
||||
HAL_StatusTypeDef Dallas_StartConvertTAll(DALLAS_HandleTypeDef *hdallas, DALLAS_WaitConvertionTypeDef waitCondition, uint8_t dallas_delay_ms);
|
||||
/* Измеряет температуру на датчике */
|
||||
HAL_StatusTypeDef Dallas_ConvertT(DALLAS_SensorHandleTypeDef *sensor, DALLAS_WaitConvertionTypeDef waitCondition);
|
||||
/* Читает измеренную датчиком температуру */
|
||||
HAL_StatusTypeDef Dallas_ReadTemperature(DALLAS_SensorHandleTypeDef *sensor);
|
||||
/* Проверяет подключен ли датчик (чтение scratchpad) */
|
||||
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
|
||||
14
john103C6T6NewVer/Core/Inc/def.h
Normal file
14
john103C6T6NewVer/Core/Inc/def.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef __DEF_H
|
||||
#define __DEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MAX_DEVICES 10
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
||||
53
john103C6T6NewVer/Core/Inc/dma.h
Normal file
53
john103C6T6NewVer/Core/Inc/dma.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file dma.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the dma.c file
|
||||
******************************************************************************
|
||||
* @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 */
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __DMA_H__
|
||||
#define __DMA_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* DMA memory to memory transfer handles -------------------------------------*/
|
||||
extern DMA_HandleTypeDef hdma_memtomem_dma1_channel1;
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_DMA_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DMA_H__ */
|
||||
|
||||
104
john103C6T6NewVer/Core/Inc/ds18b20_driver.h
Normal file
104
john103C6T6NewVer/Core/Inc/ds18b20_driver.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file ds18b20_driver.h
|
||||
* @brief This file contains all the constants parameters for the DS18B20
|
||||
* 1-Wire Digital Thermometer
|
||||
******************************************************************************
|
||||
* @attention
|
||||
* Usage:
|
||||
* Uncomment LL Driver for HAL driver
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef DS18B20_H
|
||||
#define DS18B20_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "onewire.h"
|
||||
#include "PROJ_setup.h"
|
||||
|
||||
|
||||
|
||||
/* Data Structure ------------------------------------------------------------*/
|
||||
#define DS18B20_DEVICE_AMOUNT MAX_SENSE
|
||||
|
||||
/* Register ------------------------------------------------------------------*/
|
||||
#define DS18B20_CMD_CONVERT 0x44
|
||||
#define DS18B20_CMD_ALARM_SEARCH 0xEC
|
||||
#define DS18B20_CMD_READSCRATCHPAD 0xBE
|
||||
#define DS18B20_CMD_WRITESCRATCHPAD 0x4E
|
||||
#define DS18B20_CMD_COPYSCRATCHPAD 0x48
|
||||
/* Data Structure ------------------------------------------------------------*/
|
||||
#define DS18B20_FAMILY_CODE 0x28
|
||||
|
||||
|
||||
#define DS18B20_SERIAL_NUMBER_LEN_BYTES 6
|
||||
#define DS18B20_SERIAL_NUMBER_OFFSET_BYTES 1
|
||||
|
||||
#define DS18B20_SCRATCHPAD_T_LSB_BYTE_IDX 0
|
||||
#define DS18B20_SCRATCHPAD_T_MSB_BYTE_IDX 1
|
||||
#define DS18B20_SCRATCHPAD_T_LIMIT_H_BYTE_IDX 2
|
||||
#define DS18B20_SCRATCHPAD_T_LIMIT_L_BYTE_IDX 3
|
||||
#define DS18B20_SCRATCHPAD_CONFIG_BYTE_IDX 4
|
||||
#define DS18B20_SCRATCHPAD_USER_BYTE_3_IDX 6
|
||||
#define DS18B20_SCRATCHPAD_USER_BYTE_4_IDX 7
|
||||
#define DS18B20_SCRATCHPAD_CRC_IDX 8
|
||||
|
||||
/* Bits locations for resolution */
|
||||
#define DS18B20_RESOLUTION_R1 6
|
||||
#define DS18B20_RESOLUTION_R0 5
|
||||
|
||||
#define DS18B20_DECIMAL_STEP_12BIT 0.0625
|
||||
#define DS18B20_DECIMAL_STEP_11BIT 0.125
|
||||
#define DS18B20_DECIMAL_STEP_10BIT 0.25
|
||||
#define DS18B20_DECIMAL_STEP_9BIT 0.5
|
||||
|
||||
#define DS18B20_DELAY_MS_9_BITS 94
|
||||
#define DS18B20_DELAY_MS_10_BITS 188
|
||||
#define DS18B20_DELAY_MS_11_BITS 375
|
||||
#define DS18B20_DELAY_MS_12_BITS 750
|
||||
#define DS18B20_DELAY_MS_MAX DS18B20_DELAY_MS_12_BITS
|
||||
|
||||
|
||||
/* DS18B20 Resolutions */
|
||||
typedef enum {
|
||||
DS18B20_RESOLUTION_9BITS = 0x1F,
|
||||
DS18B20_RESOLUTION_10BITS = 0x3F,
|
||||
DS18B20_RESOLUTION_11BITS = 0x5F,
|
||||
DS18B20_RESOLUTION_12BITS = 0x7F
|
||||
} DS18B20_Res_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t DevAddr[DS18B20_DEVICE_AMOUNT][8];
|
||||
} DS18B20_Drv_t;
|
||||
extern DS18B20_Drv_t DS;
|
||||
extern OneWire_t OW;
|
||||
|
||||
/* External Function ---------------------------------------------------------*/
|
||||
HAL_StatusTypeDef DS18B20_Search(DS18B20_Drv_t *DS, OneWire_t *OW);
|
||||
HAL_StatusTypeDef DS18B20_StartConvT(OneWire_t* OW, uint8_t *ROM);
|
||||
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,
|
||||
int16_t UserBytes34, uint8_t UserBytesMask);
|
||||
uint8_t DS18B20_AlarmSearch(DS18B20_Drv_t *DS, OneWire_t* OW);
|
||||
|
||||
HAL_StatusTypeDef DS18B20_SetResolution(OneWire_t* OW, uint8_t *ROM,
|
||||
DS18B20_Res_t Resolution);
|
||||
HAL_StatusTypeDef DS18B20_IsValidAddress(uint8_t *ROM);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DS18B20_H */
|
||||
49
john103C6T6NewVer/Core/Inc/gpio.h
Normal file
49
john103C6T6NewVer/Core/Inc/gpio.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file gpio.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the gpio.c file
|
||||
******************************************************************************
|
||||
* @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 */
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __GPIO_H__
|
||||
#define __GPIO_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_GPIO_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*__ GPIO_H__ */
|
||||
|
||||
52
john103C6T6NewVer/Core/Inc/i2c.h
Normal file
52
john103C6T6NewVer/Core/Inc/i2c.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file i2c.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the i2c.c file
|
||||
******************************************************************************
|
||||
* @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 */
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __I2C_H__
|
||||
#define __I2C_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern I2C_HandleTypeDef hi2c1;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_I2C1_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __I2C_H__ */
|
||||
|
||||
146
john103C6T6NewVer/Core/Inc/main.h
Normal file
146
john103C6T6NewVer/Core/Inc/main.h
Normal file
@@ -0,0 +1,146 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
***************************************************************
|
||||
* 1 2 3 4 5 6 7 8 *
|
||||
* --- +++ *
|
||||
* *
|
||||
*****************************************************************
|
||||
|
||||
|
||||
******************************************************************************
|
||||
* @file : main.h
|
||||
* @brief : Header for main.c file.
|
||||
* This file contains the common defines of the application.
|
||||
******************************************************************************
|
||||
* @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 */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MAIN_H
|
||||
#define __MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f1xx_hal.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "modbus_data.h"
|
||||
#include "PROJ_setup.h"
|
||||
#include "dallas_tools.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FuncOK=0,
|
||||
FuncERROR=1
|
||||
|
||||
}FuncStat;
|
||||
|
||||
|
||||
typedef enum {
|
||||
CONFIG_DEVICE_ID = 0,
|
||||
CONFIG_BAUDRATE,
|
||||
CONFIG_CALIBRATION,
|
||||
CONFIG_SETTINGS
|
||||
} ConfigParams;
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
STATE_OPEN_VALVE = 0, // open
|
||||
STATE_CLOSE_VALVE= 1 // close
|
||||
} ValveState;
|
||||
typedef struct
|
||||
{
|
||||
uint32_t id[2];
|
||||
float temp;
|
||||
uint16_t location;
|
||||
uint8_t t_open;
|
||||
float t_set;
|
||||
uint8_t t_close;
|
||||
uint8_t status_T_sense:1 ;
|
||||
ValveState state;
|
||||
uint16_t count;
|
||||
}TEMP_TypeDef;
|
||||
typedef struct {
|
||||
uint32_t init_tsens : 1; // Update Interrupt Flag (бит 0) — флаг переполнения/обновления
|
||||
|
||||
// ... (другие биты могут быть зарезервированы или использоваться в расширенных таймерах)
|
||||
} Flags_TypeDef;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
#define reset_blink_delay 50
|
||||
#define rest_iter 10
|
||||
#define GPIOB11_valve MB_DATA.Coils.coils[0].state_val_bit.state_val_01
|
||||
#define ralay_5v_on GPIOA->ODR&(1<<10);
|
||||
|
||||
|
||||
|
||||
extern void handle_command(char* cmd);
|
||||
typedef void (*FunctionPointer)(void);
|
||||
|
||||
uint16_t handle_valves(TEMP_TypeDef* temp_sense[MAX_SENSE]);
|
||||
void init_setpoint_all_T_sense(TEMP_TypeDef* temp_sense, int size_array);
|
||||
void iwdg_refresh(void);
|
||||
void led_blink(GPIO_TypeDef *GPIOx,uint16_t GPIO_Pin,uint8_t iter,uint16_t delay);
|
||||
FuncStat Field_modbus(MB_DataStructureTypeDef* MB_DATA, Flags_TypeDef* flag);
|
||||
FuncStat packStruct(MB_DataStructureTypeDef* MB_DATA,int sizeARR);
|
||||
void Check_Tconnect(MB_DataStructureTypeDef* MB_DATA, Flags_TypeDef* flag ,DALLAS_HandleTypeDef* hdallas, int a[50]);
|
||||
FuncStat value_control(void );
|
||||
|
||||
void reinit_t_sens(void);
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void Error_Handler(void);
|
||||
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define One_wire_Pin GPIO_PIN_15
|
||||
#define One_wire_GPIO_Port GPIOA
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
||||
77
john103C6T6NewVer/Core/Inc/onewire.h
Normal file
77
john103C6T6NewVer/Core/Inc/onewire.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file onewire.h
|
||||
* @brief This file contains all the constants parameters for the OneWire
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef ONEWIRE_H
|
||||
#define ONEWIRE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "ow_port.h"
|
||||
|
||||
/* Driver Selection ----------------------------------------------------------*/
|
||||
//#define LL_Driver
|
||||
//#define CMSIS_Driver
|
||||
/* OneWire Timings -----------------------------------------------------------*/
|
||||
#define ONEWIRE_RESET_PULSE_US 480 // Длительность импульса сброса
|
||||
#define ONEWIRE_PRESENCE_WAIT_US 70 // Ожидание ответа от датчика
|
||||
#define ONEWIRE_PRESENCE_DURATION_US 410 // Длительность сигнала присутствия
|
||||
|
||||
#define ONEWIRE_WRITE_1_US 8 // Длительность записи "1"
|
||||
#define ONEWIRE_WRITE_0_US 57 // Длительность записи "0"
|
||||
#define ONEWIRE_READ_CMD_US 2 // Время комманды чтения бита
|
||||
#define ONEWIRE_READ_DELAY_US 6 // Задержка перед считыванием бита
|
||||
#define ONEWIRE_COMMAND_SLOT_US 58 // Общее время комманды OneWire
|
||||
#define ONEWIRE_RECOVERY_TIME_US 1 // Восстановление перед следующим слотом
|
||||
/* Common Register -----------------------------------------------------------*/
|
||||
#define ONEWIRE_CMD_SEARCHROM 0xF0
|
||||
#define ONEWIRE_CMD_READROM 0x33
|
||||
#define ONEWIRE_CMD_MATCHROM 0x55
|
||||
#define ONEWIRE_CMD_SKIPROM 0xCC
|
||||
|
||||
/* Data Structure ------------------------------------------------------------*/
|
||||
typedef enum
|
||||
{
|
||||
Input,
|
||||
Output
|
||||
} PinMode;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t LastDiscrepancy;
|
||||
uint8_t LastFamilyDiscrepancy;
|
||||
uint8_t LastDeviceFlag;
|
||||
uint8_t RomByte[8];
|
||||
uint8_t RomCnt;
|
||||
uint16_t DataPin;
|
||||
GPIO_TypeDef *DataPort;
|
||||
} OneWire_t;
|
||||
|
||||
/* External Function ---------------------------------------------------------*/
|
||||
void OneWire_Init(OneWire_t* OW);
|
||||
uint8_t OneWire_Search(OneWire_t* OW, uint8_t Cmd);
|
||||
void OneWire_GetDevRom(OneWire_t* OW, uint8_t *dev);
|
||||
uint8_t OneWire_Reset(OneWire_t* OW);
|
||||
uint8_t OneWire_ReadBit(OneWire_t* OW);
|
||||
uint8_t OneWire_ReadByte(OneWire_t* OW);
|
||||
void OneWire_WriteByte(OneWire_t* OW, uint8_t byte);
|
||||
void OneWire_MatchROM(OneWire_t* OW, uint8_t *Rom);
|
||||
void OneWire_Skip(OneWire_t* OW);
|
||||
uint8_t OneWire_CRC8(uint8_t *addr, uint8_t len);
|
||||
|
||||
void OneWire_Pin_Mode(OneWire_t* OW, PinMode Mode);
|
||||
void OneWire_Pin_Level(OneWire_t* OW, uint8_t Level);
|
||||
uint8_t OneWire_Pin_Read(OneWire_t* OW);
|
||||
void OneWire_WriteBit(OneWire_t* OW, uint8_t bit);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ONEWIRE_H */
|
||||
60
john103C6T6NewVer/Core/Inc/ow_port.h
Normal file
60
john103C6T6NewVer/Core/Inc/ow_port.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file ow_port.h
|
||||
* @brief This file includes the driver for port for OneWire purposes
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef ONEWIRE_PORT_H
|
||||
#define ONEWIRE_PORT_H
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f1xx_hal.h"
|
||||
|
||||
/* I/O Port ------------------------------------------------------------------*/
|
||||
//#define LL_Driver ///< использовать CMSIS для управления ножкой
|
||||
#define CMSIS_Driver ///< использовать CMSIS для управления ножкой
|
||||
// если ничего не выбрано - используется HAL
|
||||
|
||||
|
||||
/**
|
||||
* @def OW_GPIO_Port
|
||||
* @brief Порт вывода для шины 1-Wire.
|
||||
* @details Указывает порт GPIO, к которому подключена линия данных 1-Wire (например, для DS18B20).
|
||||
*/
|
||||
#define OW_GPIO_Port GPIOA
|
||||
|
||||
/**
|
||||
* @def OW_Pin_Numb
|
||||
* @brief Номер пина в порту OW_GPIO_Port.
|
||||
* @details Используется для формирования маски пина и настройки ввода/вывода.
|
||||
*/
|
||||
#define OW_Pin_Numb 15
|
||||
|
||||
/**
|
||||
* @def OW_Pin
|
||||
* @brief Маска пина, соответствующая номеру OW_Pin_Numb.
|
||||
* @details Используется при доступе к регистрам порта для управления состоянием линии 1-Wire.
|
||||
*/
|
||||
#define OW_Pin (1<<OW_Pin_Numb)
|
||||
|
||||
/**
|
||||
* @def OW_TIM
|
||||
* @brief Аппаратный таймер для формирования временных интервалов протокола 1-Wire.
|
||||
* @details Применяется для создания точных задержек при обмене данными по шине 1-Wire.
|
||||
*/
|
||||
#define OW_TIM TIM1
|
||||
|
||||
/**
|
||||
* @def OW_TIM_1US_PERIOD
|
||||
* @brief Количество тактов таймера OW_TIM, соответствующее 1 микросекунде.
|
||||
* @details Вычисляется на основе частоты таймера. Например, для таймера с частотой 24 МГц значение будет равно 24.
|
||||
*/
|
||||
#define OW_TIM_1US_PERIOD 72
|
||||
|
||||
|
||||
/* OneWire Timings -----------------------------------------------------------*/
|
||||
void OneWire_Delay_us(uint32_t us);
|
||||
/* Common Register -----------------------------------------------------------*/
|
||||
#endif /* ONEWIRE_PORT_H */
|
||||
52
john103C6T6NewVer/Core/Inc/rtc.h
Normal file
52
john103C6T6NewVer/Core/Inc/rtc.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rtc.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the rtc.c file
|
||||
******************************************************************************
|
||||
* @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 */
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __RTC_H__
|
||||
#define __RTC_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern RTC_HandleTypeDef hrtc;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_RTC_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __RTC_H__ */
|
||||
|
||||
391
john103C6T6NewVer/Core/Inc/stm32f1xx_hal_conf.h
Normal file
391
john103C6T6NewVer/Core/Inc/stm32f1xx_hal_conf.h
Normal file
@@ -0,0 +1,391 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx_hal_conf.h
|
||||
* @brief HAL configuration file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 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 */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32F1xx_HAL_CONF_H
|
||||
#define __STM32F1xx_HAL_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* ########################## Module Selection ############################## */
|
||||
/**
|
||||
* @brief This is the list of modules to be used in the HAL driver
|
||||
*/
|
||||
|
||||
#define HAL_MODULE_ENABLED
|
||||
#define HAL_ADC_MODULE_ENABLED
|
||||
/*#define HAL_CRYP_MODULE_ENABLED */
|
||||
/*#define HAL_CAN_MODULE_ENABLED */
|
||||
/*#define HAL_CAN_LEGACY_MODULE_ENABLED */
|
||||
/*#define HAL_CEC_MODULE_ENABLED */
|
||||
/*#define HAL_CORTEX_MODULE_ENABLED */
|
||||
/*#define HAL_CRC_MODULE_ENABLED */
|
||||
/*#define HAL_DAC_MODULE_ENABLED */
|
||||
/*#define HAL_DMA_MODULE_ENABLED */
|
||||
/*#define HAL_ETH_MODULE_ENABLED */
|
||||
/*#define HAL_FLASH_MODULE_ENABLED */
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
#define HAL_I2C_MODULE_ENABLED
|
||||
/*#define HAL_I2S_MODULE_ENABLED */
|
||||
/*#define HAL_IRDA_MODULE_ENABLED */
|
||||
/*#define HAL_IWDG_MODULE_ENABLED */
|
||||
/*#define HAL_NOR_MODULE_ENABLED */
|
||||
/*#define HAL_NAND_MODULE_ENABLED */
|
||||
/*#define HAL_PCCARD_MODULE_ENABLED */
|
||||
/*#define HAL_PCD_MODULE_ENABLED */
|
||||
/*#define HAL_HCD_MODULE_ENABLED */
|
||||
/*#define HAL_PWR_MODULE_ENABLED */
|
||||
/*#define HAL_RCC_MODULE_ENABLED */
|
||||
#define HAL_RTC_MODULE_ENABLED
|
||||
/*#define HAL_SD_MODULE_ENABLED */
|
||||
/*#define HAL_MMC_MODULE_ENABLED */
|
||||
/*#define HAL_SDRAM_MODULE_ENABLED */
|
||||
/*#define HAL_SMARTCARD_MODULE_ENABLED */
|
||||
/*#define HAL_SPI_MODULE_ENABLED */
|
||||
/*#define HAL_SRAM_MODULE_ENABLED */
|
||||
#define HAL_TIM_MODULE_ENABLED
|
||||
#define HAL_UART_MODULE_ENABLED
|
||||
/*#define HAL_USART_MODULE_ENABLED */
|
||||
/*#define HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
#define HAL_CORTEX_MODULE_ENABLED
|
||||
#define HAL_DMA_MODULE_ENABLED
|
||||
#define HAL_FLASH_MODULE_ENABLED
|
||||
#define HAL_EXTI_MODULE_ENABLED
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
#define HAL_PWR_MODULE_ENABLED
|
||||
#define HAL_RCC_MODULE_ENABLED
|
||||
|
||||
/* ########################## Oscillator Values adaptation ####################*/
|
||||
/**
|
||||
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSE is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||
#define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI) value.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSI is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE 8000000U /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal Low Speed oscillator (LSI) value.
|
||||
*/
|
||||
#if !defined (LSI_VALUE)
|
||||
#define LSI_VALUE 40000U /*!< LSI Typical Value in Hz */
|
||||
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
|
||||
The real value may vary depending on the variations
|
||||
in voltage and temperature. */
|
||||
|
||||
/**
|
||||
* @brief External Low Speed oscillator (LSE) value.
|
||||
* This value is used by the UART, RTC HAL module to compute the system frequency
|
||||
*/
|
||||
#if !defined (LSE_VALUE)
|
||||
#define LSE_VALUE 32768U /*!< Value of the External oscillator in Hz*/
|
||||
#endif /* LSE_VALUE */
|
||||
|
||||
#if !defined (LSE_STARTUP_TIMEOUT)
|
||||
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
|
||||
#endif /* LSE_STARTUP_TIMEOUT */
|
||||
|
||||
/* Tip: To avoid modifying this file each time you need to use different HSE,
|
||||
=== you can define the HSE value in your toolchain compiler preprocessor. */
|
||||
|
||||
/* ########################### System Configuration ######################### */
|
||||
/**
|
||||
* @brief This is the HAL system configuration section
|
||||
*/
|
||||
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
|
||||
#define TICK_INT_PRIORITY 15U /*!< tick interrupt priority (lowest by default) */
|
||||
#define USE_RTOS 0U
|
||||
#define PREFETCH_ENABLE 1U
|
||||
|
||||
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
|
||||
#define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */
|
||||
#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */
|
||||
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */
|
||||
#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */
|
||||
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */
|
||||
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
|
||||
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
|
||||
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */
|
||||
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */
|
||||
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */
|
||||
#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */
|
||||
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */
|
||||
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */
|
||||
#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */
|
||||
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */
|
||||
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */
|
||||
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */
|
||||
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
|
||||
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */
|
||||
#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */
|
||||
#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */
|
||||
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
|
||||
|
||||
/* ########################## Assert Selection ############################## */
|
||||
/**
|
||||
* @brief Uncomment the line below to expanse the "assert_param" macro in the
|
||||
* HAL drivers code
|
||||
*/
|
||||
/* #define USE_FULL_ASSERT 1U */
|
||||
|
||||
/* ################## Ethernet peripheral configuration ##################### */
|
||||
|
||||
/* Section 1 : Ethernet peripheral configuration */
|
||||
|
||||
/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
|
||||
#define MAC_ADDR0 2U
|
||||
#define MAC_ADDR1 0U
|
||||
#define MAC_ADDR2 0U
|
||||
#define MAC_ADDR3 0U
|
||||
#define MAC_ADDR4 0U
|
||||
#define MAC_ADDR5 0U
|
||||
|
||||
/* Definition of the Ethernet driver buffers size and count */
|
||||
#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
|
||||
#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
|
||||
#define ETH_RXBUFNB 8U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
|
||||
#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
|
||||
|
||||
/* Section 2: PHY configuration section */
|
||||
|
||||
/* DP83848_PHY_ADDRESS Address*/
|
||||
#define DP83848_PHY_ADDRESS 0x01U
|
||||
/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
|
||||
#define PHY_RESET_DELAY 0x000000FFU
|
||||
/* PHY Configuration delay */
|
||||
#define PHY_CONFIG_DELAY 0x00000FFFU
|
||||
|
||||
#define PHY_READ_TO 0x0000FFFFU
|
||||
#define PHY_WRITE_TO 0x0000FFFFU
|
||||
|
||||
/* Section 3: Common PHY Registers */
|
||||
|
||||
#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
|
||||
#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
|
||||
|
||||
#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
|
||||
#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
|
||||
#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
|
||||
#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
|
||||
#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
|
||||
#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
|
||||
#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
|
||||
#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
|
||||
#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
|
||||
#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
|
||||
|
||||
#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
|
||||
#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
|
||||
#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
|
||||
|
||||
/* Section 4: Extended PHY Registers */
|
||||
#define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */
|
||||
|
||||
#define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */
|
||||
#define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */
|
||||
|
||||
/* ################## SPI peripheral configuration ########################## */
|
||||
|
||||
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
|
||||
* Activated: CRC code is present inside driver
|
||||
* Deactivated: CRC code cleaned from driver
|
||||
*/
|
||||
|
||||
#define USE_SPI_CRC 0U
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Include module's header file
|
||||
*/
|
||||
|
||||
#ifdef HAL_RCC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_rcc.h"
|
||||
#endif /* HAL_RCC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GPIO_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_gpio.h"
|
||||
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_EXTI_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_exti.h"
|
||||
#endif /* HAL_EXTI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_dma.h"
|
||||
#endif /* HAL_DMA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ETH_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_eth.h"
|
||||
#endif /* HAL_ETH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_can.h"
|
||||
#endif /* HAL_CAN_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_LEGACY_MODULE_ENABLED
|
||||
#include "Legacy/stm32f1xx_hal_can_legacy.h"
|
||||
#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CEC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_cec.h"
|
||||
#endif /* HAL_CEC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CORTEX_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_cortex.h"
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_adc.h"
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_crc.h"
|
||||
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DAC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_dac.h"
|
||||
#endif /* HAL_DAC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_flash.h"
|
||||
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SRAM_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_sram.h"
|
||||
#endif /* HAL_SRAM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NOR_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_nor.h"
|
||||
#endif /* HAL_NOR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_i2c.h"
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2S_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_i2s.h"
|
||||
#endif /* HAL_I2S_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_iwdg.h"
|
||||
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PWR_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_pwr.h"
|
||||
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RTC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_rtc.h"
|
||||
#endif /* HAL_RTC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCCARD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_pccard.h"
|
||||
#endif /* HAL_PCCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_sd.h"
|
||||
#endif /* HAL_SD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NAND_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_nand.h"
|
||||
#endif /* HAL_NAND_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_spi.h"
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TIM_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_tim.h"
|
||||
#endif /* HAL_TIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_uart.h"
|
||||
#endif /* HAL_UART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_USART_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_usart.h"
|
||||
#endif /* HAL_USART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IRDA_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_irda.h"
|
||||
#endif /* HAL_IRDA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_smartcard.h"
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_WWDG_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_wwdg.h"
|
||||
#endif /* HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_pcd.h"
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HCD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_hcd.h"
|
||||
#endif /* HAL_HCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_MMC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_mmc.h"
|
||||
#endif /* HAL_MMC_MODULE_ENABLED */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t* file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F1xx_HAL_CONF_H */
|
||||
|
||||
74
john103C6T6NewVer/Core/Inc/stm32f1xx_it.h
Normal file
74
john103C6T6NewVer/Core/Inc/stm32f1xx_it.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx_it.h
|
||||
* @brief This file contains the headers of the interrupt handlers.
|
||||
******************************************************************************
|
||||
* @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 */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32F1xx_IT_H
|
||||
#define __STM32F1xx_IT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void NMI_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void MemManage_Handler(void);
|
||||
void BusFault_Handler(void);
|
||||
void UsageFault_Handler(void);
|
||||
void SVC_Handler(void);
|
||||
void DebugMon_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
void RTC_IRQHandler(void);
|
||||
void TIM1_BRK_IRQHandler(void);
|
||||
void TIM1_UP_IRQHandler(void);
|
||||
void TIM1_TRG_COM_IRQHandler(void);
|
||||
void TIM1_CC_IRQHandler(void);
|
||||
void TIM2_IRQHandler(void);
|
||||
void TIM3_IRQHandler(void);
|
||||
void USART1_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F1xx_IT_H */
|
||||
55
john103C6T6NewVer/Core/Inc/tim.h
Normal file
55
john103C6T6NewVer/Core/Inc/tim.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file tim.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the tim.c file
|
||||
******************************************************************************
|
||||
* @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 */
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __TIM_H__
|
||||
#define __TIM_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern TIM_HandleTypeDef htim1;
|
||||
|
||||
extern TIM_HandleTypeDef htim2;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_TIM1_Init(void);
|
||||
void MX_TIM2_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __TIM_H__ */
|
||||
|
||||
52
john103C6T6NewVer/Core/Inc/usart.h
Normal file
52
john103C6T6NewVer/Core/Inc/usart.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usart.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the usart.c file
|
||||
******************************************************************************
|
||||
* @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 */
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USART_H__
|
||||
#define __USART_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern UART_HandleTypeDef huart1;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_USART1_UART_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USART_H__ */
|
||||
|
||||
129
john103C6T6NewVer/Core/Src/UART_TERM.c
Normal file
129
john103C6T6NewVer/Core/Src/UART_TERM.c
Normal file
@@ -0,0 +1,129 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "def.h"
|
||||
//extern uint8_t devices_found ;
|
||||
extern uint8_t roms[MAX_DEVICES][8];
|
||||
extern char rx_buffer[64];
|
||||
extern TEMP_TypeDef temp_sense[30];
|
||||
extern uint8_t init;
|
||||
int test_var=0;
|
||||
//void handle_command(char* cmd)
|
||||
//
|
||||
//{
|
||||
// if (strncmp(cmd, "list", 4) == 0)
|
||||
// {
|
||||
// printf("find %d devices:\r\n", devices_found);
|
||||
// for (int i = 0; i < devices_found; i++)
|
||||
// {
|
||||
// printf("Device #%d: ", i);
|
||||
// for (int j = 0; j < 8; j++)
|
||||
// printf("%02X ", roms[i][j]);
|
||||
// printf("\r\n");
|
||||
// }
|
||||
// }
|
||||
// else if (strncmp(cmd, "temp all", 8) == 0)
|
||||
// {
|
||||
// for (int i = 0; i < devices_found; i++)
|
||||
// {
|
||||
// ds_reset();
|
||||
// ds_write_byte(0x55);
|
||||
// for (int j = 0; j < 8; j++)
|
||||
// ds_write_byte(roms[i][j]);
|
||||
// ds_write_byte(0x44);
|
||||
// }
|
||||
|
||||
// HAL_Delay(750);
|
||||
|
||||
// for (int i = 0; i < devices_found; i++)
|
||||
// {
|
||||
// ds_reset();
|
||||
// ds_write_byte(0x55);
|
||||
// for (int j = 0; j < 8; j++)
|
||||
// ds_write_byte(roms[i][j]);
|
||||
// ds_write_byte(0xBE);
|
||||
// uint8_t tl = ds_read_byte();
|
||||
// uint8_t th = ds_read_byte();
|
||||
// int16_t t = (th << 8) | tl;
|
||||
// float temp = t / 16.0;
|
||||
// printf("T[%d] = %.2f C\r\n", i, temp);
|
||||
// }
|
||||
// }
|
||||
// else if (strncmp(cmd, "temp ", 5) == 0)
|
||||
// {
|
||||
// int id = atoi(&cmd[5]);
|
||||
// if (id < 0 || id >= devices_found)
|
||||
// {
|
||||
// printf("unknown ID\r\n");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// ds_reset();
|
||||
// ds_write_byte(0x55);
|
||||
// for (int j = 0; j < 8; j++)
|
||||
// ds_write_byte(roms[id][j]);
|
||||
// ds_write_byte(0x44);
|
||||
// HAL_Delay(750);
|
||||
|
||||
// ds_reset();
|
||||
// ds_write_byte(0x55);
|
||||
// for (int j = 0; j < 8; j++)
|
||||
// ds_write_byte(roms[id][j]);
|
||||
// ds_write_byte(0xBE);
|
||||
// uint8_t tl = ds_read_byte();
|
||||
// uint8_t th = ds_read_byte();
|
||||
// int16_t t = (th << 8) | tl;
|
||||
// float temp = t / 16.0;
|
||||
// printf("T[%d] = %.2f C\r\n", id, temp);
|
||||
// }
|
||||
// else if (strncmp(cmd, "ts_1_open_minus",15 ) == 0)
|
||||
// {
|
||||
// temp_sense[0].t_open-=1;
|
||||
//
|
||||
// }
|
||||
// else if (strncmp(cmd, "ts_1_open_plus",14 ) == 0)
|
||||
// {
|
||||
// temp_sense[0].t_open+=1;
|
||||
//
|
||||
// }
|
||||
// else if (strncmp(cmd, "ts_1_close_minus",16 ) == 0)
|
||||
// {
|
||||
// temp_sense[0].t_close-=1;
|
||||
//
|
||||
// }
|
||||
// else if (strncmp(cmd, "ts_1_close_plus",15 ) == 0)
|
||||
// {
|
||||
//
|
||||
// temp_sense[0].t_close+=1;
|
||||
// }
|
||||
// else if (strncmp(cmd, "init",4 ) == 0)
|
||||
// {
|
||||
// init=1;
|
||||
// printf("init %s\r\n", "OK");
|
||||
// }
|
||||
// else if
|
||||
// (strncmp(cmd, "set_temp ", 9) == 0)
|
||||
// {
|
||||
// uint8_t sense_num = (atoi(&cmd[9])&0x7c0)>>10;
|
||||
// int parse_uart=atoi(&cmd[10]);
|
||||
//
|
||||
// temp_sense[sense_num].t_set=(float)parse_uart/10.;
|
||||
// printf("temp_sense %i %s\r\n",sense_num, "OK");
|
||||
//
|
||||
//
|
||||
// }
|
||||
// else if (strncmp(cmd, "temp ", 5) == 0)
|
||||
// {
|
||||
//
|
||||
//
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// printf("unknown CMD: %s\r\n", cmd);
|
||||
// for (int i=0;i<63;i++)
|
||||
// rx_buffer[i]=0;
|
||||
//
|
||||
// }
|
||||
//}
|
||||
106
john103C6T6NewVer/Core/Src/adc.c
Normal file
106
john103C6T6NewVer/Core/Src/adc.c
Normal file
@@ -0,0 +1,106 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file adc.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the ADC instances.
|
||||
******************************************************************************
|
||||
* @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 "adc.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
ADC_HandleTypeDef hadc1;
|
||||
|
||||
/* ADC1 init function */
|
||||
void MX_ADC1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 0 */
|
||||
|
||||
/* USER CODE END ADC1_Init 0 */
|
||||
|
||||
ADC_ChannelConfTypeDef sConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 1 */
|
||||
|
||||
/* USER CODE END ADC1_Init 1 */
|
||||
|
||||
/** Common config
|
||||
*/
|
||||
hadc1.Instance = ADC1;
|
||||
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
||||
hadc1.Init.ContinuousConvMode = ENABLE;
|
||||
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc1.Init.NbrOfConversion = 1;
|
||||
if (HAL_ADC_Init(&hadc1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_VREFINT;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
|
||||
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN ADC1_Init 2 */
|
||||
|
||||
/* USER CODE END ADC1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
||||
{
|
||||
|
||||
if(adcHandle->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 0 */
|
||||
/* ADC1 clock enable */
|
||||
__HAL_RCC_ADC1_CLK_ENABLE();
|
||||
/* USER CODE BEGIN ADC1_MspInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
|
||||
{
|
||||
|
||||
if(adcHandle->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_ADC1_CLK_DISABLE();
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
649
john103C6T6NewVer/Core/Src/dallas_tools.c
Normal file
649
john103C6T6NewVer/Core/Src/dallas_tools.c
Normal file
@@ -0,0 +1,649 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file dallas_tools.c
|
||||
* @brief Драйвер для работы с датчиками температуры DS18B20
|
||||
******************************************************************************
|
||||
@details
|
||||
Библиотека предназначена для работы с цифровыми датчиками температуры DS18B20
|
||||
по однопроводному интерфейсу 1-Wire. Реализована поддержка инициализации, поиска,
|
||||
добавления и работы с несколькими датчиками.
|
||||
|
||||
@verbatim
|
||||
==============================================================================
|
||||
## Основные задачи библиотеки ##
|
||||
==============================================================================
|
||||
Эта библиотека предоставляет следующие основные функции:
|
||||
(+) Инициализация шины 1-Wire и обнаружение подключённых датчиков
|
||||
(+) Инициализация структуры датчика по:
|
||||
- ROM-адресу
|
||||
- пользовательским байтам (TH, TL, UserByte3, UserByte4)
|
||||
- порядковому номеру в списке найденных устройств
|
||||
(+) Конфигурация разрешения измерения
|
||||
(+) Чтение температуры
|
||||
(+) Замена «потерянного» датчика
|
||||
(+) Деинициализация структуры датчика
|
||||
|
||||
==============================================================================
|
||||
## Быстрый старт ##
|
||||
==============================================================================
|
||||
Пример последовательности инициализации и использования:
|
||||
|
||||
1. Определение пина и таймера для OneWire в ow_port.h:
|
||||
#define OW_GPIO_Port GPIOB
|
||||
#define OW_Pin_Numb 0
|
||||
#define OW_Pin (1<<OW_Pin_Numb)
|
||||
#define OW_TIM TIM3
|
||||
#define OW_TIM_1US_PERIOD 24
|
||||
|
||||
2. Подключение библиотеки и настройка таймеров:
|
||||
#include "dallas_tools.h"
|
||||
MX_TIM_Init();
|
||||
|
||||
3. Инициализация шины и поиск датчиков:
|
||||
Dallas_BusFirstInit(&htim);
|
||||
|
||||
4. Инициализация датчика Dallas_SensorHandleTypeDef по одному из методов:
|
||||
sens1.Init.init_func = &Dallas_SensorInitByInd; // по индексу
|
||||
sens1.Init.InitParam.Ind = 0; // порядковый номер найденного датика для инициализации
|
||||
|
||||
sens2.Init.init_func = &Dallas_SensorInitByROM; // по ROM-адресу
|
||||
sens2.Init.InitParam.ROM = 0; // ROM датика для инициализации
|
||||
|
||||
sens3.Init.init_func = &Dallas_SensorInitByUserBytes; // по пользовательским байтам
|
||||
sens3.Init.InitParam.UserBytes.UserByte1 = 1; // UseBytes датика для инициализации
|
||||
sens3.Init.InitParam.UserBytes.UserByte2 = 2; // UseBytes датика для инициализации
|
||||
sens3.Init.InitParam.UserBytes.UserByte3 = 3; // UseBytes датика для инициализации
|
||||
sens3.Init.InitParam.UserBytes.UserByte4 = 4; // UseBytes датика для инициализации
|
||||
|
||||
5. Инициализация структуруы датчика:
|
||||
Dallas_AddNewSensors(&hdallas, &sens);
|
||||
|
||||
6. Работа с датчиком:
|
||||
Dallas_StartConvertTAll(hdallas, DALLAS_WAIT_BUS, 0);
|
||||
Dallas_ReadTemperature(&sens);
|
||||
|
||||
==============================================================================
|
||||
## Требуемые зависимости ##
|
||||
==============================================================================
|
||||
Для работы библиотеки требуется:
|
||||
- Драйвер OneWire (файлы onewire.c/h и ow_port.c/.h)
|
||||
- Драйвер DS18B20 (файлы ds18b20.c/h)
|
||||
|
||||
@endverbatim
|
||||
==============================================================================
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
/* Includes ----------------------------------------------------------------*/
|
||||
|
||||
#include "dallas_tools.h"
|
||||
#include "string.h"
|
||||
|
||||
|
||||
/* Declarations and definitions --------------------------------------------*/
|
||||
DALLAS_HandleTypeDef hdallas;
|
||||
|
||||
/* Functions ---------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Функция для иниицализации шины OW для датчиков
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_BusFirstInit(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
if(htim == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
|
||||
HAL_TIM_Base_Start(htim);
|
||||
|
||||
hdallas.onewire = &OW;
|
||||
hdallas.ds_devices = &DS;
|
||||
OW.DataPin = OW_Pin;
|
||||
OW.DataPort = OW_GPIO_Port;
|
||||
/* Инициализация onewire и поиск датчиков*/
|
||||
OneWire_Init(&OW);
|
||||
|
||||
|
||||
return DS18B20_Search(&DS, &OW) != HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Функция для иниицализации нового датчика в структуре
|
||||
* @param hdallas Указатель на хендл для общения с датчиками
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_AddNewSensors(DALLAS_HandleTypeDef *hdallas, DALLAS_SensorHandleTypeDef *sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
if(hdallas == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
sensor->hdallas = hdallas;
|
||||
|
||||
result = sensor->Init.init_func(hdallas, sensor);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Функция для нахождения нового датчика на место потерянного
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_ReplaceLostedSensor(DALLAS_SensorHandleTypeDef *sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
result = Dallas_IsConnected(sensor);
|
||||
|
||||
if(sensor->isLost)
|
||||
{
|
||||
if(DS18B20_Search(sensor->hdallas->ds_devices, sensor->hdallas->onewire) != HAL_OK)
|
||||
return HAL_ERROR;
|
||||
|
||||
if(sensor->Init.init_func(sensor->hdallas, sensor) != HAL_OK)
|
||||
return HAL_ERROR;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY; // датчик не потерян
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Запускает измерение температуры на всех датчиках
|
||||
* @param hdallas Указатель на хендл для общения с датчиками
|
||||
* @param waitCondition Условие ожидания завершения преобразования
|
||||
* @param dallas_delay_ms Время ожидания окончания конверсии
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_StartConvertTAll(DALLAS_HandleTypeDef *hdallas, DALLAS_WaitConvertionTypeDef waitCondition, uint8_t dallas_delay_ms)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
uint8_t rxDummyData;
|
||||
|
||||
if(hdallas == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
// Отправка команды начала преобразования температуры
|
||||
result = DS18B20_StartConvTAll(hdallas->onewire);
|
||||
if(result != HAL_OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
// // Проверка что преобразование началось
|
||||
// if(OneWire_ReadBit(onewire) == 1)
|
||||
// return HAL_ERROR;
|
||||
|
||||
// Ожидание завершения преобразования, путем проверки шины
|
||||
if (waitCondition == DALLAS_WAIT_BUS)
|
||||
{
|
||||
result = DS18B20_WaitForEndConvertion(hdallas->onewire);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Ожидание завершения преобразования, путем задержки
|
||||
if (waitCondition == DALLAS_WAIT_DELAY)
|
||||
{
|
||||
uint32_t delayValueMs = 0;
|
||||
|
||||
switch (dallas_delay_ms)
|
||||
{
|
||||
case DALLAS_CONFIG_9_BITS:
|
||||
delayValueMs = DALLAS_DELAY_MS_9_BITS;
|
||||
break;
|
||||
|
||||
case DALLAS_CONFIG_10_BITS:
|
||||
delayValueMs = DALLAS_DELAY_MS_10_BITS;
|
||||
break;
|
||||
|
||||
case DALLAS_CONFIG_11_BITS:
|
||||
delayValueMs = DALLAS_DELAY_MS_11_BITS;
|
||||
break;
|
||||
|
||||
case DALLAS_CONFIG_12_BITS:
|
||||
delayValueMs = DALLAS_DELAY_MS_12_BITS;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
HAL_Delay(delayValueMs);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Измеряет температуру на датчике
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @param waitCondition Условие ожидания завершения преобразования
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_ConvertT(DALLAS_SensorHandleTypeDef *sensor, DALLAS_WaitConvertionTypeDef waitCondition)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
uint8_t rxDummyData;
|
||||
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor->isInitialized == 0)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* Проверка присутствует ли выбранный датчик на линии */
|
||||
result = Dallas_IsConnected(sensor);
|
||||
if (result != HAL_OK)
|
||||
return result;
|
||||
|
||||
// Отправка команды начала преобразования температуры
|
||||
result = DS18B20_StartConvT(sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM);
|
||||
if(result != HAL_OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
// Ожидание завершения преобразования, путем проверки шины
|
||||
if (waitCondition == DALLAS_WAIT_BUS)
|
||||
{
|
||||
result = DS18B20_WaitForEndConvertion(sensor->hdallas->onewire);
|
||||
if(result == HAL_TIMEOUT)
|
||||
{
|
||||
sensor->f.timeout_convertion_cnt++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Ожидание завершения преобразования, путем задержки
|
||||
if (waitCondition == DALLAS_WAIT_DELAY)
|
||||
{
|
||||
uint32_t delayValueMs = 0;
|
||||
|
||||
switch (sensor->hdallas->scratchpad.ConfigRegister)
|
||||
{
|
||||
case DALLAS_CONFIG_9_BITS:
|
||||
delayValueMs = DALLAS_DELAY_MS_9_BITS;
|
||||
break;
|
||||
|
||||
case DALLAS_CONFIG_10_BITS:
|
||||
delayValueMs = DALLAS_DELAY_MS_10_BITS;
|
||||
break;
|
||||
|
||||
case DALLAS_CONFIG_11_BITS:
|
||||
delayValueMs = DALLAS_DELAY_MS_11_BITS;
|
||||
break;
|
||||
|
||||
case DALLAS_CONFIG_12_BITS:
|
||||
delayValueMs = DALLAS_DELAY_MS_12_BITS;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
HAL_Delay(delayValueMs);
|
||||
}
|
||||
|
||||
/* Не считываем температуру, если не выбрано ожидание окончания преобразования */
|
||||
if(waitCondition != DALLAS_WAIT_NONE)
|
||||
{
|
||||
result = Dallas_ReadTemperature(sensor);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Читает измеренную датчиком температуру
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_ReadTemperature(DALLAS_SensorHandleTypeDef *sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor->isInitialized == 0)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* Проверка присутствует ли выбранный датчик на линии */
|
||||
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);
|
||||
|
||||
if (result != HAL_OK)
|
||||
{
|
||||
sensor->f.read_temperature_err_cnt++;
|
||||
return result;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Проверяет подключен ли датчик (чтение scratchpad)
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_IsConnected(DALLAS_SensorHandleTypeDef *sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
result = Dallas_ReadScratchpad(sensor);
|
||||
|
||||
if (result == HAL_OK)
|
||||
{
|
||||
sensor->isConnected = 1;
|
||||
sensor->isLost = 0;
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
//sensor->temperature = 0;
|
||||
if(sensor->isConnected == 1)
|
||||
{
|
||||
sensor->f.disconnect_cnt++;
|
||||
}
|
||||
|
||||
sensor->isLost = 1;
|
||||
if (sensor->f.disconnect_cnt>8)
|
||||
sensor->isConnected = 0;//13.02 сделал паузу чтоб не стробил типа фильтр
|
||||
|
||||
|
||||
// Dallas_ReplaceLostedSensor(sensor);
|
||||
return HAL_BUSY; // использую busy, чтобы отличать ситуацию от HAL_ERROR
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Записывает пользовательские байты
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @param UserBytes12 Пользовательские байты 1 и 2
|
||||
* @param UserBytes34 Пользовательские байты 3 и 4
|
||||
* @param UserBytesMask Маска, какие байты записывать, а какие нет
|
||||
* @retval HAL Status
|
||||
* @details старший байт - UserByte4/UserByte2, младший - UserByte3/UserByte1.
|
||||
*/
|
||||
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;
|
||||
|
||||
/* Проверка присутствует ли выбранный датчик на линии */
|
||||
result = Dallas_IsConnected(sensor);
|
||||
if (result != HAL_OK)
|
||||
return result;
|
||||
|
||||
result = DS18B20_WriteUserBytes(sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM, UserBytes12, UserBytes34, UserBytesMask);
|
||||
if (result != HAL_OK)
|
||||
{
|
||||
sensor->f.write_err_cnt++;
|
||||
return result;
|
||||
}
|
||||
result = Dallas_ReadScratchpad(sensor);
|
||||
if (result != HAL_OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Инициализирует структуру датчика по ROM
|
||||
* @param hdallas Указатель на хендл для общения с датчиками
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_SensorInitByROM(DALLAS_HandleTypeDef *hdallas, DALLAS_SensorHandleTypeDef *sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
if(hdallas == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
uint8_t ROM[8] = {0};
|
||||
ROM[0] = (sensor->Init.InitParam.ROM >> (7*8)) & 0xFF;
|
||||
ROM[1] = (sensor->Init.InitParam.ROM >> (6*8)) & 0xFF;
|
||||
ROM[2] = (sensor->Init.InitParam.ROM >> (5*8)) & 0xFF;
|
||||
ROM[3] = (sensor->Init.InitParam.ROM >> (4*8)) & 0xFF;
|
||||
ROM[4] = (sensor->Init.InitParam.ROM >> (3*8)) & 0xFF;
|
||||
ROM[5] = (sensor->Init.InitParam.ROM >> (2*8)) & 0xFF;
|
||||
ROM[6] = (sensor->Init.InitParam.ROM >> (1*8)) & 0xFF;
|
||||
ROM[7] = (sensor->Init.InitParam.ROM >> (0*8)) & 0xFF;
|
||||
|
||||
if(DS18B20_IsValidAddress(ROM) != HAL_OK)
|
||||
return HAL_ERROR;
|
||||
|
||||
uint8_t comparebytes = DALLAS_ROM_SIZE;
|
||||
int ROM_ind = 0;
|
||||
for(int i = 0; i < hdallas->onewire->RomCnt; i++)
|
||||
{
|
||||
comparebytes = DALLAS_ROM_SIZE;
|
||||
for(int rom_byte = 0; rom_byte < DALLAS_ROM_SIZE; rom_byte++)
|
||||
{
|
||||
if(hdallas->ds_devices->DevAddr[i][rom_byte] == ROM[rom_byte])
|
||||
comparebytes--;
|
||||
}
|
||||
if(comparebytes == 0)
|
||||
{
|
||||
ROM_ind = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Проверка присутствует ли выбранный датчик на линии */
|
||||
if(comparebytes == 0)
|
||||
{
|
||||
|
||||
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices->DevAddr[ROM_ind]);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Инициализирует структуру датчика по пользовательским байтам
|
||||
* @param hdallas Указатель на хендл для общения с датчиками
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_SensorInitByUserBytes(DALLAS_HandleTypeDef *hdallas, DALLAS_SensorHandleTypeDef *sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
if(hdallas == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
uint8_t UserByte1 = sensor->Init.InitParam.UserBytes.UserByte1;
|
||||
uint8_t UserByte2 = sensor->Init.InitParam.UserBytes.UserByte2;
|
||||
uint8_t UserByte3 = sensor->Init.InitParam.UserBytes.UserByte3;
|
||||
uint8_t UserByte4 = sensor->Init.InitParam.UserBytes.UserByte4;
|
||||
uint8_t UserByte12Cmp = 0;
|
||||
uint8_t UserByte34Cmp = 0;
|
||||
|
||||
for(int i = 0; i < hdallas->onewire->RomCnt; i++)
|
||||
{
|
||||
/* Проверка присутствует ли выбранный датчик на линии */
|
||||
result = DS18B20_ReadScratchpad(hdallas->onewire, (uint8_t *)&hdallas->ds_devices->DevAddr[i], (uint8_t *)&hdallas->scratchpad);
|
||||
if (result != HAL_OK)
|
||||
return result;
|
||||
|
||||
/* Сравнение UserByte1 и UserByte2, если они не равны нулю */
|
||||
if(UserByte1 | UserByte2)
|
||||
{
|
||||
if( (hdallas->scratchpad.tHighRegister == UserByte1) &&
|
||||
(hdallas->scratchpad.tLowRegister == UserByte2))
|
||||
{
|
||||
UserByte12Cmp = 1;
|
||||
}
|
||||
}/* Если сравнение UserByte1 и UserByte2 не выбрано, то считаем что они совпадают */
|
||||
else
|
||||
{
|
||||
UserByte12Cmp = 1;
|
||||
}
|
||||
/* Сравнение UserByte3 и UserByte4, если они не равны нулю */
|
||||
if(UserByte3 | UserByte4)
|
||||
{
|
||||
if( (hdallas->scratchpad.UserByte3 == UserByte3) &&
|
||||
(hdallas->scratchpad.UserByte4 == UserByte4))
|
||||
{
|
||||
UserByte34Cmp = 1;
|
||||
}
|
||||
}/* Если сравнение UserByte3 и UserByte4 не выбрано, то считаем что они одинаковые */
|
||||
else
|
||||
{
|
||||
UserByte34Cmp = 1;
|
||||
}
|
||||
/* Если нашли нужный датчик - завершаем поиск */
|
||||
if(UserByte12Cmp && UserByte34Cmp)
|
||||
{
|
||||
// sensor->isInitialized = 1;
|
||||
// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
||||
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices->DevAddr[i]);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
sensor->sensROM = 0;
|
||||
/* Возвращаем ошибку если не нашли */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Инициализирует структуру датчика по порядковому номеру
|
||||
* @param hdallas Указатель на хендл для общения с датчиками
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @retval HAL Status
|
||||
* @details Порядковый номер датчика в списке найденных.
|
||||
* Т.е. каким по счету этот датчик был найден
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_SensorInitByInd(DALLAS_HandleTypeDef *hdallas, DALLAS_SensorHandleTypeDef *sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
if(hdallas == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices->DevAddr[sensor->Init.InitParam.Ind]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Инициализирует датчик для работы
|
||||
* @param hdallas Указатель на хендл для общения с датчиками
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @param ROM ROM датчика, который надо инициализировать
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_SensorInit(DALLAS_HandleTypeDef *hdallas, DALLAS_SensorHandleTypeDef *sensor, uint8_t (*ROM)[DALLAS_ROM_SIZE])
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
if(hdallas == 0)
|
||||
return HAL_ERROR;
|
||||
|
||||
sensor->hdallas = hdallas;
|
||||
sensor->sensROM = 0;
|
||||
sensor->sensROM = *(uint64_t *)(ROM);
|
||||
// for(int i = 0; i < DALLAS_ROM_SIZE; i++)
|
||||
// sensor->sensROM |= ((uint64_t)(*ROM)[i] << (56 - 8*i));
|
||||
|
||||
/* Проверка присутствует ли выбранный датчик на линии */
|
||||
result = Dallas_ReadScratchpad(sensor);
|
||||
if (result == HAL_OK)
|
||||
{
|
||||
/* Установка разрешения */
|
||||
result = DS18B20_SetResolution(hdallas->onewire, (uint8_t *)ROM, sensor->Init.Resolution);
|
||||
if (result == HAL_OK)
|
||||
{
|
||||
sensor->isInitialized = 1;
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
sensor->isInitialized = 0;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sensor->isInitialized = 0;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Деинициализирует структуру датчика
|
||||
* @param sensor Указатель на структуру датчика
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_SensorDeInit(DALLAS_SensorHandleTypeDef *sensor)
|
||||
{
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
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;
|
||||
}
|
||||
67
john103C6T6NewVer/Core/Src/dma.c
Normal file
67
john103C6T6NewVer/Core/Src/dma.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file dma.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of all the requested memory to memory DMA transfers.
|
||||
******************************************************************************
|
||||
* @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 "dma.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Configure DMA */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
DMA_HandleTypeDef hdma_memtomem_dma1_channel1;
|
||||
|
||||
/**
|
||||
* Enable DMA controller clock
|
||||
* Configure DMA for memory to memory transfers
|
||||
* hdma_memtomem_dma1_channel1
|
||||
*/
|
||||
void MX_DMA_Init(void)
|
||||
{
|
||||
|
||||
/* DMA controller clock enable */
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
|
||||
/* Configure DMA request hdma_memtomem_dma1_channel1 on DMA1_Channel1 */
|
||||
hdma_memtomem_dma1_channel1.Instance = DMA1_Channel1;
|
||||
hdma_memtomem_dma1_channel1.Init.Direction = DMA_MEMORY_TO_MEMORY;
|
||||
hdma_memtomem_dma1_channel1.Init.PeriphInc = DMA_PINC_ENABLE;
|
||||
hdma_memtomem_dma1_channel1.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_memtomem_dma1_channel1.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_memtomem_dma1_channel1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
hdma_memtomem_dma1_channel1.Init.Mode = DMA_NORMAL;
|
||||
hdma_memtomem_dma1_channel1.Init.Priority = DMA_PRIORITY_LOW;
|
||||
if (HAL_DMA_Init(&hdma_memtomem_dma1_channel1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
607
john103C6T6NewVer/Core/Src/ds18b20_driver.c
Normal file
607
john103C6T6NewVer/Core/Src/ds18b20_driver.c
Normal file
@@ -0,0 +1,607 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file ds18b20_driver.c
|
||||
* @brief This file includes the HAL/LL driver for DS18B20 1-Wire Digital
|
||||
* Thermometer
|
||||
******************************************************************************
|
||||
*/
|
||||
#include "ds18b20_driver.h"
|
||||
|
||||
DS18B20_Drv_t DS;
|
||||
OneWire_t OW;
|
||||
|
||||
/**
|
||||
* @brief The function is used to check valid DS18B20 ROM
|
||||
* @retval Return in OK = 1, Failed = 0
|
||||
* @param ROM Pointer to ROM number
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_IsValidAddress(uint8_t *ROM)
|
||||
{
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
uint8_t check_family = (*ROM == DS18B20_FAMILY_CODE);
|
||||
/* Calculate CRC */
|
||||
uint8_t crc = OneWire_CRC8(ROM, 7);
|
||||
uint8_t check_crc = (crc == ROM[7]);
|
||||
/* Checks if first byte is equal to DS18B20's family code */
|
||||
if(check_family && check_crc)
|
||||
return HAL_OK;
|
||||
else
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/**
|
||||
* @brief The function is used to check valid DS18B20 ROM
|
||||
* @retval Return in OK = 1, Failed = 0
|
||||
* @param ROM Pointer to ROM number
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_IsValid(uint8_t *ROM)
|
||||
{
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
if(*ROM == DS18B20_FAMILY_CODE)
|
||||
return HAL_OK;
|
||||
else
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used to get resolution
|
||||
* @retval Return value in 9 - 12
|
||||
* @param OW OneWire HandleTypedef
|
||||
* @param ROM Pointer to ROM number
|
||||
*/
|
||||
uint8_t DS18B20_GetResolution(OneWire_t* OW, uint8_t *ROM) {
|
||||
uint8_t conf;
|
||||
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* Check valid ROM */
|
||||
if (DS18B20_IsValid(ROM) != HAL_OK)
|
||||
return 0;
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Select ROM number */
|
||||
OneWire_MatchROM(OW, ROM);
|
||||
|
||||
/* Read scratchpad command by onewire protocol */
|
||||
OneWire_WriteByte(OW, DS18B20_CMD_READSCRATCHPAD);
|
||||
|
||||
/* Ignore first 4 bytes */
|
||||
OneWire_ReadByte(OW);
|
||||
OneWire_ReadByte(OW);
|
||||
OneWire_ReadByte(OW);
|
||||
OneWire_ReadByte(OW);
|
||||
|
||||
/* 5th byte of scratchpad is configuration register */
|
||||
conf = OneWire_ReadByte(OW);
|
||||
|
||||
/* Return 9 - 12 value according to number of bits */
|
||||
return ((conf & 0x60) >> 5) + 9;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used as set resolution
|
||||
* @retval status in OK = 1, Failed = 0
|
||||
* @param OW OneWire HandleTypedef
|
||||
* @param ROM Pointer to ROM number
|
||||
* @param Resolution Resolution in 9 - 12
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_SetResolution(OneWire_t* OW, uint8_t *ROM,
|
||||
DS18B20_Res_t Resolution)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
uint8_t th, tl, conf;
|
||||
|
||||
/* Check valid ROM */
|
||||
if (DS18B20_IsValid(ROM) != HAL_OK)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Select ROM number */
|
||||
OneWire_MatchROM(OW, ROM);
|
||||
|
||||
/* Read scratchpad command by onewire protocol */
|
||||
OneWire_WriteByte(OW, DS18B20_CMD_READSCRATCHPAD);
|
||||
|
||||
/* Ignore first 2 bytes */
|
||||
OneWire_ReadByte(OW);
|
||||
OneWire_ReadByte(OW);
|
||||
|
||||
th = OneWire_ReadByte(OW);
|
||||
tl = OneWire_ReadByte(OW);
|
||||
conf = OneWire_ReadByte(OW);
|
||||
|
||||
/* Set choosed resolution */
|
||||
conf = Resolution;
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Select ROM number */
|
||||
OneWire_MatchROM(OW, ROM);
|
||||
|
||||
/* Write scratchpad command by onewire protocol, only th, tl and conf
|
||||
* register can be written */
|
||||
OneWire_WriteByte(OW, DS18B20_CMD_WRITESCRATCHPAD);
|
||||
|
||||
/* Write bytes */
|
||||
OneWire_WriteByte(OW, th);
|
||||
OneWire_WriteByte(OW, tl);
|
||||
OneWire_WriteByte(OW, conf);
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Select ROM number */
|
||||
OneWire_MatchROM(OW, ROM);
|
||||
|
||||
/* Copy scratchpad to EEPROM of DS18B20 */
|
||||
OneWire_WriteByte(OW, DS18B20_CMD_COPYSCRATCHPAD);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used as start selected ROM device
|
||||
* @retval status in OK = 1, Failed = 0
|
||||
* @param OW OneWire HandleTypedef
|
||||
* @param ROM Pointer to ROM number
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_StartConvT(OneWire_t* OW, uint8_t *ROM)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* Check if device is DS18B20 */
|
||||
if(DS18B20_IsValid(ROM) != HAL_OK)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Select ROM number */
|
||||
OneWire_MatchROM(OW, ROM);
|
||||
|
||||
/* Start temperature conversion */
|
||||
OneWire_WriteByte(OW, DS18B20_CMD_CONVERT);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
/**
|
||||
* @brief The function is used as start all ROM device
|
||||
* @param OW OneWire HandleTypedef
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_StartConvTAll(OneWire_t* OW)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* Reset pulse */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Skip rom */
|
||||
OneWire_WriteByte(OW, ONEWIRE_CMD_SKIPROM);
|
||||
|
||||
/* Start conversion on all connected devices */
|
||||
OneWire_WriteByte(OW, DS18B20_CMD_CONVERT);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used as read temreature from device and store in selected
|
||||
* destination
|
||||
* @retval status in OK = 1, Failed = 0
|
||||
* @param OW OneWire HandleTypedef
|
||||
* @param ROM Pointer to ROM number
|
||||
* @param Destination Pointer to return value
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_CalcTemperature(OneWire_t* OW, uint8_t *ROM, uint8_t *Scratchpad, float *Destination)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
if(Scratchpad == NULL)
|
||||
return HAL_ERROR;
|
||||
if(Destination == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
uint16_t temperature;
|
||||
uint8_t resolution;
|
||||
int8_t digit, minus = 0;
|
||||
float decimal;
|
||||
|
||||
/* Check if device is DS18B20 */
|
||||
if (DS18B20_IsValid(ROM) != HAL_OK)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* First two bytes of scratchpad are temperature values */
|
||||
temperature = Scratchpad[0] | (Scratchpad[1] << 8);
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Check if temperature is negative */
|
||||
if (temperature & 0x8000) {
|
||||
/* Two's complement, temperature is negative */
|
||||
temperature = ~temperature + 1;
|
||||
minus = 1;
|
||||
}
|
||||
|
||||
/* Get sensor resolution */
|
||||
resolution = Scratchpad[4];
|
||||
|
||||
/* Store temperature integer digits and decimal digits */
|
||||
digit = temperature >> 4;
|
||||
digit |= ((temperature >> 8) & 0x7) << 4;
|
||||
|
||||
/* Store decimal digits */
|
||||
switch (resolution) {
|
||||
case DS18B20_RESOLUTION_9BITS: {
|
||||
decimal = (temperature >> 3) & 0x01;
|
||||
decimal *= (float)DS18B20_DECIMAL_STEP_9BIT;
|
||||
} break;
|
||||
case DS18B20_RESOLUTION_10BITS: {
|
||||
decimal = (temperature >> 2) & 0x03;
|
||||
decimal *= (float)DS18B20_DECIMAL_STEP_10BIT;
|
||||
} break;
|
||||
case DS18B20_RESOLUTION_11BITS: {
|
||||
decimal = (temperature >> 1) & 0x07;
|
||||
decimal *= (float)DS18B20_DECIMAL_STEP_11BIT;
|
||||
} break;
|
||||
case DS18B20_RESOLUTION_12BITS: {
|
||||
decimal = temperature & 0x0F;
|
||||
decimal *= (float)DS18B20_DECIMAL_STEP_12BIT;
|
||||
} break;
|
||||
default: {
|
||||
*Destination = 0;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for negative part */
|
||||
decimal = digit + decimal;
|
||||
if (minus) {
|
||||
decimal = 0 - decimal;
|
||||
}
|
||||
|
||||
/* Set to pointer */
|
||||
*Destination = decimal;
|
||||
|
||||
/* Return HAL_OK, temperature valid */
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The function is used as read scratchpad from device
|
||||
* @retval status in OK = 1, Failed = 0
|
||||
* @param OW OneWire HandleTypedef
|
||||
* @param ROM Pointer to ROM number
|
||||
* @param Destination Pointer to Scratchpad array
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_ReadScratchpad(OneWire_t* OW, uint8_t *ROM, uint8_t *Scratchpad)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
if(Scratchpad == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Select ROM number */
|
||||
OneWire_MatchROM(OW, ROM);
|
||||
|
||||
/* Read scratchpad command by onewire protocol */
|
||||
OneWire_WriteByte(OW, DS18B20_CMD_READSCRATCHPAD);
|
||||
|
||||
/* Get data */
|
||||
for (int i = 0; i < 9; i++) {
|
||||
/* Read byte by byte */
|
||||
Scratchpad[i] = OneWire_ReadByte(OW);
|
||||
}
|
||||
|
||||
/* Calculate CRC */
|
||||
uint8_t crc = OneWire_CRC8(Scratchpad, 8);
|
||||
|
||||
/* Check if CRC is ok */
|
||||
if (crc != Scratchpad[8]) {
|
||||
/* CRC invalid */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The function is used to wait for end of convertion
|
||||
* @param OW OneWire HandleTypedef
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_WaitForEndConvertion(OneWire_t* OW)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
uint32_t tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait until line is released, then coversion is completed */
|
||||
while(OneWire_ReadBit(OW) == 0)
|
||||
{
|
||||
if(HAL_GetTick() - tickstart > DS18B20_DELAY_MS_MAX)
|
||||
return HAL_TIMEOUT; // end of convertion has not come
|
||||
}
|
||||
return HAL_OK; // convertion done
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
||||
* selected device
|
||||
* @retval status in OK = 1, Failed = 0
|
||||
* @param OW OneWire HandleTypedef
|
||||
* @param ROM Pointer to ROM number
|
||||
* @param Low Low temperature alarm, value > -55, 0 = reset
|
||||
* @param High High temperature alarm,, value < 125, 0 = reset
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_SetTempAlarm(OneWire_t* OW, uint8_t *ROM, int8_t Low,
|
||||
int8_t High)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
uint8_t tl, th, conf;
|
||||
|
||||
/* Check if device is DS18B20 */
|
||||
if (DS18B20_IsValid(ROM) != HAL_OK)
|
||||
return HAL_ERROR;
|
||||
|
||||
Low = ((Low < -55) || (Low == 0)) ? -55 : Low;
|
||||
High = ((High > 125) || (High == 0)) ? 125 : High;
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Select ROM number */
|
||||
OneWire_MatchROM(OW, ROM);
|
||||
|
||||
/* Read scratchpad command by onewire protocol */
|
||||
OneWire_WriteByte(OW, DS18B20_CMD_READSCRATCHPAD);
|
||||
|
||||
/* Ignore first 2 bytes */
|
||||
OneWire_ReadByte(OW);
|
||||
OneWire_ReadByte(OW);
|
||||
|
||||
th = OneWire_ReadByte(OW);
|
||||
tl = OneWire_ReadByte(OW);
|
||||
conf = OneWire_ReadByte(OW);
|
||||
|
||||
th = (uint8_t)High;
|
||||
tl = (uint8_t)Low;
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Select ROM number */
|
||||
OneWire_MatchROM(OW, ROM);
|
||||
|
||||
/* Write scratchpad command by onewire protocol, only th, tl and conf
|
||||
* register can be written */
|
||||
OneWire_WriteByte(OW, DS18B20_CMD_WRITESCRATCHPAD);
|
||||
|
||||
/* Write bytes */
|
||||
OneWire_WriteByte(OW, th);
|
||||
OneWire_WriteByte(OW, tl);
|
||||
OneWire_WriteByte(OW, conf);
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Select ROM number */
|
||||
OneWire_MatchROM(OW, ROM);
|
||||
|
||||
/* Copy scratchpad to EEPROM of DS18B20 */
|
||||
OneWire_WriteByte(OW, DS18B20_CMD_COPYSCRATCHPAD);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used as set user bytes with mask
|
||||
* @retval status in OK = 1, Failed = 0
|
||||
* @param OW OneWire HandleTypedef
|
||||
* @param ROM Pointer to ROM number
|
||||
* @param UserBytes12 First 2 User Bytes (tHigh and tLow)
|
||||
* @param UserBytes34 Second 2 User Bytes
|
||||
* @param UserBytesMask Which User Bytes write, and which ignore
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_WriteUserBytes(OneWire_t* OW, uint8_t *ROM, int16_t UserBytes12,
|
||||
int16_t UserBytes34, uint8_t UserBytesMask)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
uint8_t ub1, ub2, conf, ub3, ub4;
|
||||
uint8_t UserByte1 = UserBytes12 & 0xFF;
|
||||
uint8_t UserByte2 = UserBytes12 >> 8;
|
||||
uint8_t UserByte3 = UserBytes34 & 0xFF;
|
||||
uint8_t UserByte4 = UserBytes34 >> 8;
|
||||
|
||||
/* Check if device is DS18B20 */
|
||||
if (DS18B20_IsValid(ROM) != HAL_OK)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Select ROM number */
|
||||
OneWire_MatchROM(OW, ROM);
|
||||
|
||||
/* Read scratchpad command by onewire protocol */
|
||||
OneWire_WriteByte(OW, DS18B20_CMD_READSCRATCHPAD);
|
||||
|
||||
/* Ignore first 2 bytes */
|
||||
OneWire_ReadByte(OW);
|
||||
OneWire_ReadByte(OW);
|
||||
|
||||
ub1 = OneWire_ReadByte(OW);
|
||||
ub2 = OneWire_ReadByte(OW);
|
||||
conf = OneWire_ReadByte(OW);
|
||||
OneWire_ReadByte(OW);
|
||||
ub3 = OneWire_ReadByte(OW);
|
||||
ub4 = OneWire_ReadByte(OW);
|
||||
|
||||
/* If user bytes in mask */
|
||||
if(UserBytesMask & (1<<0))
|
||||
{
|
||||
ub1 = UserByte1;
|
||||
}
|
||||
if(UserBytesMask & (1<<1))
|
||||
{
|
||||
ub2 = UserByte2;
|
||||
}
|
||||
if(UserBytesMask & (1<<2))
|
||||
{
|
||||
ub3 = UserByte3;
|
||||
}
|
||||
if(UserBytesMask & (1<<3))
|
||||
{
|
||||
ub4 = UserByte4;
|
||||
}
|
||||
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Select ROM number */
|
||||
OneWire_MatchROM(OW, ROM);
|
||||
|
||||
/* Write scratchpad command by onewire protocol, only th, tl and conf
|
||||
* register can be written */
|
||||
OneWire_WriteByte(OW, DS18B20_CMD_WRITESCRATCHPAD);
|
||||
|
||||
/* Write bytes */
|
||||
OneWire_WriteByte(OW, ub1);
|
||||
OneWire_WriteByte(OW, ub2);
|
||||
OneWire_WriteByte(OW, conf);
|
||||
OneWire_WriteByte(OW, ub3);
|
||||
OneWire_WriteByte(OW, ub4);
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
/* Select ROM number */
|
||||
OneWire_MatchROM(OW, ROM);
|
||||
|
||||
/* Copy scratchpad to EEPROM of DS18B20 */
|
||||
OneWire_WriteByte(OW, DS18B20_CMD_COPYSCRATCHPAD);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
///**
|
||||
// * @brief The function is used as search device that had temperature alarm
|
||||
// * triggered and store it in DS18B20 alarm data structure
|
||||
// * @retval status of search, OK = 1, Failed = 0
|
||||
// * @param DS DS18B20 HandleTypedef
|
||||
// * @param OW OneWire HandleTypedef
|
||||
// */
|
||||
//uint8_t DS18B20_AlarmSearch(DS18B20_Drv_t *DS, OneWire_t* OW)
|
||||
//{
|
||||
// uint8_t t = 0;
|
||||
|
||||
// /* Reset Alarm in DS */
|
||||
// for(uint8_t i = 0; i < OW->RomCnt; i++)
|
||||
// {
|
||||
// for(uint8_t j = 0; j < 8; j++)
|
||||
// {
|
||||
// DS->AlmAddr[i][j] = 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /* Start alarm search */
|
||||
// while (OneWire_Search(OW, DS18B20_CMD_ALARM_SEARCH))
|
||||
// {
|
||||
// /* Store ROM of device which has alarm flag set */
|
||||
// OneWire_GetDevRom(OW, DS->AlmAddr[t]);
|
||||
// t++;
|
||||
// }
|
||||
// return (t > 0) ? 1 : 0;
|
||||
//}
|
||||
|
||||
/**
|
||||
* @brief The function is used to initialize the DS18B20 sensor, and search
|
||||
* for all ROM along the line. Store in DS18B20 data structure
|
||||
* @retval Rom detect status, OK = 1, No Rom detected = 0
|
||||
* @param DS DS18B20 HandleTypedef
|
||||
* @param OW OneWire HandleTypedef
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_Search(DS18B20_Drv_t *DS, OneWire_t *OW)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
|
||||
OW->RomCnt = 0;
|
||||
/* Search all OneWire devices ROM */
|
||||
while(1)
|
||||
{
|
||||
/* Start searching for OneWire devices along the line */
|
||||
if(OneWire_Search(OW, ONEWIRE_CMD_SEARCHROM) != 1) break;
|
||||
|
||||
/* Get device ROM */
|
||||
OneWire_GetDevRom(OW, DS->DevAddr[OW->RomCnt]);
|
||||
|
||||
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;
|
||||
else
|
||||
return HAL_BUSY;
|
||||
}
|
||||
99
john103C6T6NewVer/Core/Src/gpio.c
Normal file
99
john103C6T6NewVer/Core/Src/gpio.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file gpio.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of all used GPIO pins.
|
||||
******************************************************************************
|
||||
* @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 "gpio.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Configure GPIO */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/** Configure pins as
|
||||
* Analog
|
||||
* Input
|
||||
* Output
|
||||
* EVENT_OUT
|
||||
* EXTI
|
||||
*/
|
||||
void MX_GPIO_Init(void)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4
|
||||
|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|One_wire_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_10
|
||||
|GPIO_PIN_11, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin : PC13 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_13;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PA0 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PA1 PA2 PA3 PA4
|
||||
PA5 PA6 PA7 One_wire_Pin */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4
|
||||
|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|One_wire_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PB0 PB1 PB2 PB10
|
||||
PB11 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_10
|
||||
|GPIO_PIN_11;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
117
john103C6T6NewVer/Core/Src/i2c.c
Normal file
117
john103C6T6NewVer/Core/Src/i2c.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file i2c.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the I2C instances.
|
||||
******************************************************************************
|
||||
* @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 "i2c.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
I2C_HandleTypeDef hi2c1;
|
||||
|
||||
/* I2C1 init function */
|
||||
void MX_I2C1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN I2C1_Init 0 */
|
||||
|
||||
/* USER CODE END I2C1_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN I2C1_Init 1 */
|
||||
|
||||
/* USER CODE END I2C1_Init 1 */
|
||||
hi2c1.Instance = I2C1;
|
||||
hi2c1.Init.ClockSpeed = 100000;
|
||||
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
hi2c1.Init.OwnAddress1 = 0;
|
||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hi2c1.Init.OwnAddress2 = 0;
|
||||
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN I2C1_Init 2 */
|
||||
|
||||
/* USER CODE END I2C1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(i2cHandle->Instance==I2C1)
|
||||
{
|
||||
/* USER CODE BEGIN I2C1_MspInit 0 */
|
||||
|
||||
/* USER CODE END I2C1_MspInit 0 */
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**I2C1 GPIO Configuration
|
||||
PB8 ------> I2C1_SCL
|
||||
PB9 ------> I2C1_SDA
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
__HAL_AFIO_REMAP_I2C1_ENABLE();
|
||||
|
||||
/* I2C1 clock enable */
|
||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||
/* USER CODE BEGIN I2C1_MspInit 1 */
|
||||
|
||||
/* USER CODE END I2C1_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle)
|
||||
{
|
||||
|
||||
if(i2cHandle->Instance==I2C1)
|
||||
{
|
||||
/* USER CODE BEGIN I2C1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END I2C1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_I2C1_CLK_DISABLE();
|
||||
|
||||
/**I2C1 GPIO Configuration
|
||||
PB8 ------> I2C1_SCL
|
||||
PB9 ------> I2C1_SDA
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_9);
|
||||
|
||||
/* USER CODE BEGIN I2C1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END I2C1_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
898
john103C6T6NewVer/Core/Src/main.c
Normal file
898
john103C6T6NewVer/Core/Src/main.c
Normal file
@@ -0,0 +1,898 @@
|
||||
/* 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 <stdio.h>
|
||||
#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);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
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;i<RECORD_SIZE;i++)
|
||||
{
|
||||
flash_buff[i]=i;
|
||||
|
||||
}
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
|
||||
|
||||
// if (MB_DATA.Coils.relay_struct[0].state_val_bit.Temp11_relay_isOn)
|
||||
// {
|
||||
// MB_DATA.Coils.relay_struct[0].state_val_bit.Temp11_relay_isOn = 0;
|
||||
// BufferState_t state = buffer_init();
|
||||
// uint32_t idx = (state.write_index ) % RECORDS_PER_PAGE;
|
||||
// FlashRecord_t* record = buffer_read_record(idx);
|
||||
|
||||
// }
|
||||
// if (MB_DATA.Coils.relay_struct[0].state_val_bit.Temp10_relay_isOn)
|
||||
// {
|
||||
// MB_DATA.Coils.relay_struct[0].state_val_bit.Temp10_relay_isOn = 0;
|
||||
// FlashRecord_t new_record;
|
||||
// new_record.timestamp = HAL_GetTick();
|
||||
// memcpy(new_record.data, flash_buff, sizeof(new_record.data));
|
||||
|
||||
// HAL_StatusTypeDef status = buffer_write_record(&new_record, &buffer_state);
|
||||
|
||||
// if (status == HAL_OK)
|
||||
// {
|
||||
// // printf("Record written successfully\n");
|
||||
// GPIOC->ODR |= 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; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
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++)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> ROM-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//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 */
|
||||
540
john103C6T6NewVer/Core/Src/main.c.orig
Normal file
540
john103C6T6NewVer/Core/Src/main.c.orig
Normal file
@@ -0,0 +1,540 @@
|
||||
/* 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 "can.h"
|
||||
#include "i2c.h"
|
||||
#include "rtc.h"
|
||||
#include "spi.h"
|
||||
#include "tim.h"
|
||||
#include "usart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "dallas_tools.h"
|
||||
|
||||
#include "def.h"
|
||||
#include <stdio.h>
|
||||
#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 */
|
||||
|
||||
/* 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_CAN_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_RTC_Init();
|
||||
MX_SPI1_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);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
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();
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
|
||||
|
||||
if (MB_DATA.Coils.relay_struct[0].state_val_bit.Temp11_relay_isOn)
|
||||
{
|
||||
MB_DATA.Coils.relay_struct[0].state_val_bit.Temp11_relay_isOn=0;
|
||||
BufferState_t state = buffer_init();
|
||||
uint32_t idx = (state.write_index ) % RECORDS_PER_PAGE;
|
||||
FlashRecord_t* record = buffer_read_record(idx);
|
||||
|
||||
}
|
||||
if (MB_DATA.Coils.relay_struct[0].state_val_bit.Temp10_relay_isOn)
|
||||
{
|
||||
MB_DATA.Coils.relay_struct[0].state_val_bit.Temp10_relay_isOn = 0;
|
||||
FlashRecord_t new_record;
|
||||
new_record.timestamp = HAL_GetTick();
|
||||
memset(new_record.data, (uint8_t)*flash_buff, sizeof(new_record.data));
|
||||
|
||||
HAL_StatusTypeDef status = buffer_write_record(&new_record, &buffer_state);
|
||||
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
// printf("Record written successfully\n");
|
||||
GPIOC->ODR|=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; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
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++)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> ROM-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//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.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].temperature < sens[i].set_temp - sens[i].hyst)
|
||||
|
||||
{
|
||||
|
||||
MB_DATA.Coils.coils[0].all |= 1 << i;
|
||||
MB_DATA.Coils.coils[1].all &= ~(1 << i);
|
||||
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
|
||||
if (sens[i].temperature > sens[i].set_temp + sens[i].hyst)
|
||||
{
|
||||
|
||||
MB_DATA.Coils.coils[0].all &= ~(1 << i);
|
||||
MB_DATA.Coils.coils[1].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 */
|
||||
379
john103C6T6NewVer/Core/Src/onewire.c
Normal file
379
john103C6T6NewVer/Core/Src/onewire.c
Normal file
@@ -0,0 +1,379 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file onewire.c
|
||||
* @brief This file includes the HAL/LL driver for OneWire devices
|
||||
******************************************************************************
|
||||
*/
|
||||
#include "onewire.h"
|
||||
|
||||
/**
|
||||
* @brief The internal function is used to write bit
|
||||
* @param OW OneWire HandleTypedef
|
||||
* @param bit bit in 0 or 1
|
||||
*/
|
||||
void OneWire_WriteBit(OneWire_t* OW, uint8_t bit)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return;
|
||||
#ifndef ONEWIRE_UART_H
|
||||
__disable_irq();
|
||||
if(bit)
|
||||
{
|
||||
/* Set line low */
|
||||
OneWire_Pin_Level(OW, 0);
|
||||
OneWire_Pin_Mode(OW, Output);
|
||||
|
||||
/* Forming pulse */
|
||||
OneWire_Delay_us(ONEWIRE_WRITE_1_US);
|
||||
|
||||
/* Release line (pull up line) */
|
||||
OneWire_Pin_Mode(OW, Input);
|
||||
|
||||
/* Wait for 55 us and release the line */
|
||||
OneWire_Delay_us(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_WRITE_1_US);
|
||||
OneWire_Pin_Mode(OW, Input);
|
||||
}else{
|
||||
/* Set line low */
|
||||
OneWire_Pin_Level(OW, 0);
|
||||
OneWire_Pin_Mode(OW, Output);
|
||||
|
||||
/* Forming pulse */
|
||||
OneWire_Delay_us(ONEWIRE_WRITE_0_US);
|
||||
|
||||
/* Release line (pull up line) */
|
||||
OneWire_Pin_Mode(OW, Input);
|
||||
|
||||
/* Wait for 5 us and release the line */
|
||||
OneWire_Delay_us(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_WRITE_0_US);
|
||||
OneWire_Pin_Mode(OW, Input);
|
||||
}
|
||||
__enable_irq();
|
||||
#else
|
||||
OneWireUART_ProcessBit(onewire_uart, bit);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used to read bit
|
||||
* @retval bit
|
||||
* @param OW OneWire HandleTypedef
|
||||
*/
|
||||
uint8_t OneWire_ReadBit(OneWire_t* OW)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return 0;
|
||||
|
||||
__disable_irq();
|
||||
uint8_t bit = 0;
|
||||
#ifndef ONEWIRE_UART_H
|
||||
/* Line low */
|
||||
OneWire_Pin_Level(OW, 0);
|
||||
OneWire_Pin_Mode(OW, Output);
|
||||
OneWire_Delay_us(ONEWIRE_READ_CMD_US);
|
||||
|
||||
/* Release line */
|
||||
OneWire_Pin_Mode(OW, Input);
|
||||
OneWire_Delay_us(ONEWIRE_READ_DELAY_US);
|
||||
|
||||
/* Read line value */
|
||||
bit = OneWire_Pin_Read(OW);
|
||||
|
||||
/* Wait 50us to complete 60us period */
|
||||
OneWire_Delay_us(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_READ_CMD_US - ONEWIRE_READ_DELAY_US);
|
||||
__enable_irq();
|
||||
#else
|
||||
bit = OneWireUART_ProcessBit(onewire_uart, 1);
|
||||
#endif
|
||||
/* Return bit value */
|
||||
return bit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used to write byte
|
||||
* @param OW OneWire HandleTypedef
|
||||
* @param byte byte to write
|
||||
*/
|
||||
void OneWire_WriteByte(OneWire_t* OW, uint8_t byte)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return;
|
||||
|
||||
#ifndef ONEWIRE_UART_H
|
||||
uint8_t bit = 8;
|
||||
/* Write 8 bits */
|
||||
while (bit--) {
|
||||
/* LSB bit is first */
|
||||
OneWire_WriteBit(OW, byte & 0x01);
|
||||
byte >>= 1;
|
||||
}
|
||||
#else
|
||||
OneWireUART_ProcessByte(onewire_uart, byte);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used to read byte
|
||||
* @retval byte from device
|
||||
* @param OW OneWire HandleTypedef
|
||||
*/
|
||||
uint8_t OneWire_ReadByte(OneWire_t* OW)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return 0;
|
||||
|
||||
uint8_t byte = 0;
|
||||
#ifndef ONEWIRE_UART_H
|
||||
uint8_t bit = 8;
|
||||
while (bit--) {
|
||||
byte >>= 1;
|
||||
byte |= (OneWire_ReadBit(OW) << 7);
|
||||
}
|
||||
#else
|
||||
byte = OneWireUART_ProcessByte(onewire_uart, 0xFF);
|
||||
#endif
|
||||
|
||||
return byte;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used to reset device
|
||||
* @retval respond from device
|
||||
* @param OW OneWire HandleTypedef
|
||||
*/
|
||||
uint8_t OneWire_Reset(OneWire_t* OW)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return 1;
|
||||
|
||||
#ifndef ONEWIRE_UART_H
|
||||
/* Line low, and wait 480us */
|
||||
OneWire_Pin_Level(OW, 0);
|
||||
OneWire_Pin_Mode(OW, Output);
|
||||
OneWire_Delay_us(ONEWIRE_RESET_PULSE_US);
|
||||
|
||||
/* Release line and wait for 70us */
|
||||
OneWire_Pin_Mode(OW, Input);
|
||||
OneWire_Delay_us(ONEWIRE_PRESENCE_WAIT_US);
|
||||
|
||||
/* Check bit value */
|
||||
uint8_t rslt = OneWire_Pin_Read(OW);
|
||||
|
||||
/* Delay for 410 us */
|
||||
OneWire_Delay_us(ONEWIRE_PRESENCE_DURATION_US);
|
||||
#else
|
||||
|
||||
uint8_t rslt = 0;
|
||||
if(OneWireUART_Reset(onewire_uart) == HAL_OK)
|
||||
rslt = 0;
|
||||
else
|
||||
rslt = 1;
|
||||
#endif
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used to search device
|
||||
* @retval Search result
|
||||
* @param OW OneWire HandleTypedef
|
||||
*/
|
||||
uint8_t OneWire_Search(OneWire_t* OW, uint8_t Cmd)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return 0;
|
||||
|
||||
uint8_t id_bit_number = 1;
|
||||
uint8_t last_zero = 0;
|
||||
uint8_t rom_byte_number = 0;
|
||||
uint8_t search_result = 0;
|
||||
uint8_t rom_byte_mask = 1;
|
||||
uint8_t id_bit, cmp_id_bit, search_direction;
|
||||
|
||||
/* if the last call was not the last one */
|
||||
if (!OW->LastDeviceFlag)
|
||||
{
|
||||
if (OneWire_Reset(OW))
|
||||
{
|
||||
OW->LastDiscrepancy = 0;
|
||||
OW->LastDeviceFlag = 0;
|
||||
OW->LastFamilyDiscrepancy = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// issue the search command
|
||||
OneWire_WriteByte(OW, Cmd);
|
||||
|
||||
// loop to do the search
|
||||
do {
|
||||
// read a bit and its complement
|
||||
id_bit = OneWire_ReadBit(OW);
|
||||
cmp_id_bit = OneWire_ReadBit(OW);
|
||||
|
||||
// check for no devices on 1-wire
|
||||
if ((id_bit == 1) && (cmp_id_bit == 1))
|
||||
{
|
||||
break;
|
||||
} else {
|
||||
// all devices coupled have 0 or 1
|
||||
if (id_bit != cmp_id_bit)
|
||||
{
|
||||
search_direction = id_bit; // bit write value for search
|
||||
} else {
|
||||
/* if this discrepancy if before the Last Discrepancy
|
||||
* on a previous next then pick the same as last time */
|
||||
if (id_bit_number < OW->LastDiscrepancy)
|
||||
{
|
||||
search_direction = ((OW->RomByte[rom_byte_number] & rom_byte_mask) > 0);
|
||||
} else {
|
||||
// if equal to last pick 1, if not then pick 0
|
||||
search_direction = (id_bit_number == OW->LastDiscrepancy);
|
||||
}
|
||||
|
||||
// if 0 was picked then record its position in LastZero
|
||||
if (search_direction == 0)
|
||||
{
|
||||
last_zero = id_bit_number;
|
||||
|
||||
// check for Last discrepancy in family
|
||||
if (last_zero < 9)
|
||||
{
|
||||
OW->LastFamilyDiscrepancy = last_zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* set or clear the bit in the ROM byte rom_byte_number
|
||||
* with mask rom_byte_mask */
|
||||
if (search_direction == 1)
|
||||
{
|
||||
OW->RomByte[rom_byte_number] |= rom_byte_mask;
|
||||
} else {
|
||||
OW->RomByte[rom_byte_number] &= ~rom_byte_mask;
|
||||
}
|
||||
|
||||
// serial number search direction write bit
|
||||
OneWire_WriteBit(OW, search_direction);
|
||||
|
||||
/* increment the byte counter id_bit_number and shift the
|
||||
* mask rom_byte_mask */
|
||||
id_bit_number++;
|
||||
rom_byte_mask <<= 1;
|
||||
|
||||
/* if the mask is 0 then go to new SerialNum byte
|
||||
* rom_byte_number and reset mask */
|
||||
if (rom_byte_mask == 0)
|
||||
{
|
||||
rom_byte_number++;
|
||||
rom_byte_mask = 1;
|
||||
}
|
||||
}
|
||||
} while (rom_byte_number < 8); /* loop until through all ROM bytes 0-7
|
||||
if the search was successful then */
|
||||
|
||||
if (!(id_bit_number < 65))
|
||||
{
|
||||
/* search successful so set LastDiscrepancy, LastDeviceFlag,
|
||||
* search_result */
|
||||
OW->LastDiscrepancy = last_zero;
|
||||
// check for last device
|
||||
if (OW->LastDiscrepancy == 0) {
|
||||
OW->LastDeviceFlag = 1;
|
||||
}
|
||||
search_result = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* if no device found then reset counters so next 'search' will be like a
|
||||
* first */
|
||||
if (!search_result || !OW->RomByte[0])
|
||||
{
|
||||
OW->LastDiscrepancy = 0;
|
||||
OW->LastDeviceFlag = 0;
|
||||
OW->LastFamilyDiscrepancy = 0;
|
||||
search_result = 0;
|
||||
}
|
||||
|
||||
return search_result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used get ROM full address
|
||||
* @param OW OneWire HandleTypedef
|
||||
* @param ROM Pointer to device ROM
|
||||
*/
|
||||
void OneWire_GetDevRom(OneWire_t* OW, uint8_t *ROM)
|
||||
{
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
*(ROM + i) = OW->RomByte[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used to initialize OneWire Communication
|
||||
* @param OW OneWire HandleTypedef
|
||||
*/
|
||||
void OneWire_Init(OneWire_t* OW)
|
||||
{
|
||||
OneWire_Pin_Mode(OW, Output);
|
||||
OneWire_Pin_Level(OW, 1);
|
||||
OneWire_Delay_us(1000);
|
||||
OneWire_Pin_Level(OW, 0);
|
||||
OneWire_Delay_us(1000);
|
||||
OneWire_Pin_Level(OW, 1);
|
||||
OneWire_Delay_us(2000);
|
||||
|
||||
/* Reset the search state */
|
||||
OW->LastDiscrepancy = 0;
|
||||
OW->LastDeviceFlag = 0;
|
||||
OW->LastFamilyDiscrepancy = 0;
|
||||
OW->RomCnt = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used selected specific device ROM
|
||||
* @param OW OneWire HandleTypedef
|
||||
* @param ROM Pointer to device ROM
|
||||
*/
|
||||
void OneWire_MatchROM(OneWire_t* OW, uint8_t *ROM)
|
||||
{
|
||||
OneWire_WriteByte(OW, ONEWIRE_CMD_MATCHROM);
|
||||
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
OneWire_WriteByte(OW, *(ROM + i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used to access to all ROM
|
||||
* @param OW OneWire HandleTypedef
|
||||
*/
|
||||
void OneWire_Skip(OneWire_t* OW)
|
||||
{
|
||||
OneWire_WriteByte(OW, ONEWIRE_CMD_SKIPROM);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The function is used check CRC
|
||||
* @param Addr Pointer to address
|
||||
* @param ROM Number of byte
|
||||
*/
|
||||
uint8_t OneWire_CRC8(uint8_t *Addr, uint8_t Len)
|
||||
{
|
||||
uint8_t crc = 0;
|
||||
uint8_t inbyte, i, mix;
|
||||
|
||||
while (Len--)
|
||||
{
|
||||
inbyte = *Addr++;
|
||||
|
||||
for (i = 8; i; i--)
|
||||
{
|
||||
mix = (crc ^ inbyte) & 0x01;
|
||||
crc >>= 1;
|
||||
crc ^= (mix) ? 0x8C : 0;
|
||||
inbyte >>= 1;
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
122
john103C6T6NewVer/Core/Src/ow_port.c
Normal file
122
john103C6T6NewVer/Core/Src/ow_port.c
Normal file
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file ow_port.c
|
||||
* @brief This file includes the driver for port for OneWire purposes
|
||||
******************************************************************************
|
||||
*/
|
||||
#include "ow_port.h"
|
||||
#include "onewire.h"
|
||||
#include "tim.h"
|
||||
uint32_t pin_pos = (OW_Pin_Numb < 8) ? (OW_Pin_Numb * 4) : ((OW_Pin_Numb - 8) * 4);
|
||||
|
||||
/**
|
||||
* @brief The internal function is used as gpio pin mode
|
||||
* @param OW OneWire HandleTypedef
|
||||
* @param Mode Input or Output
|
||||
*/
|
||||
void OneWire_Pin_Mode(OneWire_t* OW, PinMode Mode)
|
||||
{
|
||||
#ifdef CMSIS_Driver
|
||||
volatile uint32_t *config_reg = (OW_Pin_Numb < 8) ? &(OW->DataPort->CRL) : &(OW->DataPort->CRH);
|
||||
// —брос текущих 4 бит (CNF + MODE)
|
||||
*config_reg &= ~(0xF << pin_pos);
|
||||
|
||||
if (Mode == Input)
|
||||
{
|
||||
// ¬ход с подт¤жкой или без Ц например, CNF = 0b01, MODE = 0b00
|
||||
// «десь устанавливаем вход с подт¤жкой:
|
||||
*config_reg |= (0x8 << pin_pos); // CNF=10, MODE=00 (вход с подт¤жкой)
|
||||
OW->DataPort->ODR |= (1 << OW_Pin_Numb); // ¬ключить подт¤жку вверх
|
||||
}
|
||||
else
|
||||
{
|
||||
// ¬ыход push-pull, 2 ћ√ц Ц MODE = 0b10, CNF = 0b00
|
||||
*config_reg |= (0x2 << pin_pos);
|
||||
}
|
||||
#else
|
||||
#ifdef LL_Driver
|
||||
if(Mode == Input)
|
||||
{
|
||||
LL_GPIO_SetPinMode(OW->DataPort, OW->DataPin, LL_GPIO_MODE_INPUT);
|
||||
}else{
|
||||
LL_GPIO_SetPinMode(OW->DataPort, OW->DataPin, LL_GPIO_MODE_OUTPUT);
|
||||
}
|
||||
#else
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
GPIO_InitStruct.Pin = OW->DataPin;
|
||||
if(Mode == Input)
|
||||
{
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
}else{
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
}
|
||||
HAL_GPIO_Init(OW->DataPort, &GPIO_InitStruct);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The internal function is used as gpio pin level
|
||||
* @param OW OneWire HandleTypedef
|
||||
* @param Mode Level: Set/High = 1, Reset/Low = 0
|
||||
*/
|
||||
void OneWire_Pin_Level(OneWire_t* OW, uint8_t Level)
|
||||
{
|
||||
#ifdef CMSIS_Driver
|
||||
if (Level != GPIO_PIN_RESET)
|
||||
{
|
||||
OW->DataPort->BSRR = OW->DataPin;
|
||||
}
|
||||
else
|
||||
{
|
||||
OW->DataPort->BSRR = (uint32_t)OW->DataPin << 16u;
|
||||
}
|
||||
#else
|
||||
#ifdef LL_Driver
|
||||
if(Level == 1)
|
||||
{
|
||||
LL_GPIO_SetOutputPin(OW->DataPort, OW->DataPin);
|
||||
}else{
|
||||
LL_GPIO_ResetOutputPin(OW->DataPort, OW->DataPin);
|
||||
}
|
||||
#else
|
||||
HAL_GPIO_WritePin(OW->DataPort, OW->DataPin, Level);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The internal function is used to read data pin
|
||||
* @retval Pin level status
|
||||
* @param OW OneWire HandleTypedef
|
||||
*/
|
||||
uint8_t OneWire_Pin_Read(OneWire_t* OW)
|
||||
{
|
||||
#ifdef CMSIS_Driver
|
||||
return ((OW->DataPort->IDR & OW->DataPin) != 0x00U) ? 1 : 0;
|
||||
#else
|
||||
#ifdef LL_Driver
|
||||
return ((OW->DataPort->IDR & OW->DataPin) != 0x00U) ? 1 : 0;
|
||||
#else
|
||||
return HAL_GPIO_ReadPin(OW->DataPort, OW->DataPin);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t tim_1us_period = OW_TIM_1US_PERIOD;
|
||||
void OneWire_Delay_us(uint32_t us)
|
||||
{
|
||||
uint32_t ticks = us * tim_1us_period;
|
||||
uint16_t start = OW_TIM->CNT;
|
||||
uint32_t elapsed = 0;
|
||||
uint16_t prev = start;
|
||||
|
||||
while (elapsed < ticks)
|
||||
{
|
||||
uint16_t curr = OW_TIM->CNT;
|
||||
uint16_t delta = (uint16_t)(curr - prev); // учЄт переполнени¤
|
||||
elapsed += delta;
|
||||
prev = curr;
|
||||
}
|
||||
}
|
||||
127
john103C6T6NewVer/Core/Src/rtc.c
Normal file
127
john103C6T6NewVer/Core/Src/rtc.c
Normal file
@@ -0,0 +1,127 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rtc.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the RTC instances.
|
||||
******************************************************************************
|
||||
* @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 "rtc.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
RTC_HandleTypeDef hrtc;
|
||||
|
||||
/* RTC init function */
|
||||
void MX_RTC_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN RTC_Init 0 */
|
||||
|
||||
/* USER CODE END RTC_Init 0 */
|
||||
|
||||
RTC_TimeTypeDef sTime = {0};
|
||||
RTC_DateTypeDef DateToUpdate = {0};
|
||||
|
||||
/* USER CODE BEGIN RTC_Init 1 */
|
||||
|
||||
/* USER CODE END RTC_Init 1 */
|
||||
|
||||
/** Initialize RTC Only
|
||||
*/
|
||||
hrtc.Instance = RTC;
|
||||
hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
|
||||
hrtc.Init.OutPut = RTC_OUTPUTSOURCE_SECOND;
|
||||
if (HAL_RTC_Init(&hrtc) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Check_RTC_BKUP */
|
||||
|
||||
/* USER CODE END Check_RTC_BKUP */
|
||||
|
||||
/** Initialize RTC and set the Time and Date
|
||||
*/
|
||||
sTime.Hours = 0x0;
|
||||
sTime.Minutes = 0x0;
|
||||
sTime.Seconds = 0x0;
|
||||
|
||||
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;
|
||||
DateToUpdate.Month = RTC_MONTH_JANUARY;
|
||||
DateToUpdate.Date = 0x1;
|
||||
DateToUpdate.Year = 0x0;
|
||||
|
||||
if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN RTC_Init 2 */
|
||||
|
||||
/* USER CODE END RTC_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
|
||||
{
|
||||
|
||||
if(rtcHandle->Instance==RTC)
|
||||
{
|
||||
/* USER CODE BEGIN RTC_MspInit 0 */
|
||||
|
||||
/* USER CODE END RTC_MspInit 0 */
|
||||
HAL_PWR_EnableBkUpAccess();
|
||||
/* Enable BKP CLK enable for backup registers */
|
||||
__HAL_RCC_BKP_CLK_ENABLE();
|
||||
/* RTC clock enable */
|
||||
__HAL_RCC_RTC_ENABLE();
|
||||
|
||||
/* RTC interrupt Init */
|
||||
HAL_NVIC_SetPriority(RTC_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(RTC_IRQn);
|
||||
/* USER CODE BEGIN RTC_MspInit 1 */
|
||||
|
||||
/* USER CODE END RTC_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
|
||||
{
|
||||
|
||||
if(rtcHandle->Instance==RTC)
|
||||
{
|
||||
/* USER CODE BEGIN RTC_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END RTC_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_RTC_DISABLE();
|
||||
|
||||
/* RTC interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(RTC_IRQn);
|
||||
/* USER CODE BEGIN RTC_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END RTC_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
86
john103C6T6NewVer/Core/Src/stm32f1xx_hal_msp.c
Normal file
86
john103C6T6NewVer/Core/Src/stm32f1xx_hal_msp.c
Normal file
@@ -0,0 +1,86 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx_hal_msp.c
|
||||
* @brief This file provides code for the MSP Initialization
|
||||
* and de-Initialization codes.
|
||||
******************************************************************************
|
||||
* @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"
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Define */
|
||||
|
||||
/* USER CODE END Define */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Macro */
|
||||
|
||||
/* USER CODE END Macro */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* External functions --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ExternalFunctions */
|
||||
|
||||
/* USER CODE END ExternalFunctions */
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
/**
|
||||
* Initializes the Global MSP.
|
||||
*/
|
||||
void HAL_MspInit(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN MspInit 0 */
|
||||
|
||||
/* USER CODE END MspInit 0 */
|
||||
|
||||
__HAL_RCC_AFIO_CLK_ENABLE();
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
|
||||
/* System interrupt init*/
|
||||
|
||||
/** NOJTAG: JTAG-DP Disabled and SW-DP Enabled
|
||||
*/
|
||||
__HAL_AFIO_REMAP_SWJ_NOJTAG();
|
||||
|
||||
/* USER CODE BEGIN MspInit 1 */
|
||||
|
||||
/* USER CODE END MspInit 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
138
john103C6T6NewVer/Core/Src/stm32f1xx_hal_timebase_tim.c
Normal file
138
john103C6T6NewVer/Core/Src/stm32f1xx_hal_timebase_tim.c
Normal file
@@ -0,0 +1,138 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx_hal_timebase_tim.c
|
||||
* @brief HAL time base based on the hardware TIM.
|
||||
******************************************************************************
|
||||
* @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 "stm32f1xx_hal.h"
|
||||
#include "stm32f1xx_hal_tim.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
TIM_HandleTypeDef htim3;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void TIM3_IRQHandler(void);
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief This function configures the TIM3 as a time base source.
|
||||
* The time source is configured to have 1ms time base with a dedicated
|
||||
* Tick interrupt priority.
|
||||
* @note This function is called automatically at the beginning of program after
|
||||
* reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
|
||||
* @param TickPriority: Tick interrupt priority.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
{
|
||||
RCC_ClkInitTypeDef clkconfig;
|
||||
uint32_t uwTimclock, uwAPB1Prescaler = 0U;
|
||||
|
||||
uint32_t uwPrescalerValue = 0U;
|
||||
uint32_t pFLatency;
|
||||
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Enable TIM3 clock */
|
||||
__HAL_RCC_TIM3_CLK_ENABLE();
|
||||
|
||||
/* Get clock configuration */
|
||||
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
|
||||
|
||||
/* Get APB1 prescaler */
|
||||
uwAPB1Prescaler = clkconfig.APB1CLKDivider;
|
||||
/* Compute TIM3 clock */
|
||||
if (uwAPB1Prescaler == RCC_HCLK_DIV1)
|
||||
{
|
||||
uwTimclock = HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
else
|
||||
{
|
||||
uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
|
||||
/* Compute the prescaler value to have TIM3 counter clock equal to 1MHz */
|
||||
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
|
||||
|
||||
/* Initialize TIM3 */
|
||||
htim3.Instance = TIM3;
|
||||
|
||||
/* Initialize TIMx peripheral as follow:
|
||||
* Period = [(TIM3CLK/1000) - 1]. to have a (1/1000) s time base.
|
||||
* Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
|
||||
* ClockDivision = 0
|
||||
* Counter direction = Up
|
||||
*/
|
||||
htim3.Init.Period = (1000000U / 1000U) - 1U;
|
||||
htim3.Init.Prescaler = uwPrescalerValue;
|
||||
htim3.Init.ClockDivision = 0;
|
||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
|
||||
status = HAL_TIM_Base_Init(&htim3);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Start the TIM time Base generation in interrupt mode */
|
||||
status = HAL_TIM_Base_Start_IT(&htim3);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Enable the TIM3 global Interrupt */
|
||||
HAL_NVIC_EnableIRQ(TIM3_IRQn);
|
||||
/* Configure the SysTick IRQ priority */
|
||||
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
|
||||
{
|
||||
/* Configure the TIM IRQ priority */
|
||||
HAL_NVIC_SetPriority(TIM3_IRQn, TickPriority, 0U);
|
||||
uwTickPrio = TickPriority;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Suspend Tick increment.
|
||||
* @note Disable the tick increment by disabling TIM3 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SuspendTick(void)
|
||||
{
|
||||
/* Disable TIM3 update Interrupt */
|
||||
__HAL_TIM_DISABLE_IT(&htim3, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume Tick increment.
|
||||
* @note Enable the tick increment by Enabling TIM3 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ResumeTick(void)
|
||||
{
|
||||
/* Enable TIM3 Update interrupt */
|
||||
__HAL_TIM_ENABLE_IT(&htim3, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
330
john103C6T6NewVer/Core/Src/stm32f1xx_it.c
Normal file
330
john103C6T6NewVer/Core/Src/stm32f1xx_it.c
Normal file
@@ -0,0 +1,330 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @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 "stm32f1xx_it.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "modbus.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern RTC_HandleTypeDef hrtc;
|
||||
extern TIM_HandleTypeDef htim1;
|
||||
extern TIM_HandleTypeDef htim2;
|
||||
extern UART_HandleTypeDef huart1;
|
||||
extern TIM_HandleTypeDef htim3;
|
||||
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/******************************************************************************/
|
||||
/* Cortex-M3 Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
|
||||
|
||||
/* USER CODE END NonMaskableInt_IRQn 0 */
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END NonMaskableInt_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END HardFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
|
||||
/* USER CODE END W1_HardFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
|
||||
|
||||
/* USER CODE END MemoryManagement_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
|
||||
/* USER CODE END W1_MemoryManagement_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Prefetch fault, memory access fault.
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN BusFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END BusFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
|
||||
/* USER CODE END W1_BusFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Undefined instruction or illegal state.
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN UsageFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END UsageFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
|
||||
/* USER CODE END W1_UsageFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System service call via SWI instruction.
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SVCall_IRQn 0 */
|
||||
|
||||
/* USER CODE END SVCall_IRQn 0 */
|
||||
/* USER CODE BEGIN SVCall_IRQn 1 */
|
||||
|
||||
/* USER CODE END SVCall_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Debug monitor.
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 0 */
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Pendable request for system service.
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN PendSV_IRQn 0 */
|
||||
|
||||
/* USER CODE END PendSV_IRQn 0 */
|
||||
/* USER CODE BEGIN PendSV_IRQn 1 */
|
||||
|
||||
/* USER CODE END PendSV_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SysTick_IRQn 0 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 0 */
|
||||
|
||||
/* USER CODE BEGIN SysTick_IRQn 1 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 1 */
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* STM32F1xx Peripheral Interrupt Handlers */
|
||||
/* Add here the Interrupt Handlers for the used peripherals. */
|
||||
/* For the available peripheral interrupt handler names, */
|
||||
/* please refer to the startup file (startup_stm32f1xx.s). */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles RTC global interrupt.
|
||||
*/
|
||||
void RTC_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN RTC_IRQn 0 */
|
||||
|
||||
/* USER CODE END RTC_IRQn 0 */
|
||||
HAL_RTCEx_RTCIRQHandler(&hrtc);
|
||||
/* USER CODE BEGIN RTC_IRQn 1 */
|
||||
|
||||
/* USER CODE END RTC_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM1 break interrupt.
|
||||
*/
|
||||
void TIM1_BRK_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_BRK_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM1_BRK_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim1);
|
||||
/* USER CODE BEGIN TIM1_BRK_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM1_BRK_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM1 update interrupt.
|
||||
*/
|
||||
void TIM1_UP_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_UP_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM1_UP_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim1);
|
||||
/* USER CODE BEGIN TIM1_UP_IRQn 1 */
|
||||
|
||||
//GPIOC->ODR^=(1<<13);
|
||||
/* USER CODE END TIM1_UP_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM1 trigger and commutation interrupts.
|
||||
*/
|
||||
void TIM1_TRG_COM_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_TRG_COM_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM1_TRG_COM_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim1);
|
||||
/* USER CODE BEGIN TIM1_TRG_COM_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM1_TRG_COM_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM1 capture compare interrupt.
|
||||
*/
|
||||
void TIM1_CC_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_CC_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM1_CC_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim1);
|
||||
/* USER CODE BEGIN TIM1_CC_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM1_CC_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM2 global interrupt.
|
||||
*/
|
||||
void TIM2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM2_IRQn 0 */
|
||||
RS_TIM_Handler(&hmodbus1);
|
||||
return;
|
||||
/* USER CODE END TIM2_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim2);
|
||||
/* USER CODE BEGIN TIM2_IRQn 1 */
|
||||
//RS_TIM_Handler(&hmodbus1);
|
||||
/* USER CODE END TIM2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM3 global interrupt.
|
||||
*/
|
||||
void TIM3_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM3_IRQn 0 */
|
||||
static uint8_t first_in=1;
|
||||
/* USER CODE END TIM3_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim3);
|
||||
/* USER CODE BEGIN TIM3_IRQn 1 */
|
||||
if (first_in)
|
||||
{
|
||||
first_in=0;
|
||||
}
|
||||
|
||||
/* USER CODE END TIM3_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USART1 global interrupt.
|
||||
*/
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN USART1_IRQn 0 */
|
||||
RS_UART_Handler(&hmodbus1);
|
||||
return;
|
||||
/* USER CODE END USART1_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart1);
|
||||
/* USER CODE BEGIN USART1_IRQn 1 */
|
||||
//RS_UART_Handler(&hmodbus1);
|
||||
|
||||
|
||||
/* USER CODE END USART1_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user