add iddle irq
This commit is contained in:
@@ -50,15 +50,25 @@ void MX_GPIO_Init(void)
|
||||
__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|GPIO_PIN_8
|
||||
|GPIO_PIN_9|GPIO_PIN_10|One_wire_Pin, GPIO_PIN_SET);
|
||||
|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
|
||||
|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
|
||||
|GPIO_PIN_15, GPIO_PIN_SET);
|
||||
|GPIO_PIN_15, 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;
|
||||
@@ -68,10 +78,10 @@ void MX_GPIO_Init(void)
|
||||
|
||||
/*Configure GPIO pins : PA1 PA2 PA3 PA4
|
||||
PA5 PA6 PA7 PA8
|
||||
PA9 PA10 PAPin */
|
||||
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|GPIO_PIN_10|One_wire_Pin;
|
||||
|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;
|
||||
|
||||
@@ -69,6 +69,7 @@ uint8_t ralay_5v_on_var=0;
|
||||
uint8_t uart_byte = 0;
|
||||
uint8_t first_in=1;
|
||||
DALLAS_SensorHandleTypeDef sens[30];
|
||||
int init_sens=0;
|
||||
|
||||
|
||||
/* USER CODE END PM */
|
||||
@@ -95,7 +96,6 @@ void SystemClock_Config(void);
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
@@ -121,7 +121,6 @@ int main(void)
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
|
||||
MX_TIM1_Init();
|
||||
MX_USART1_UART_Init();
|
||||
MX_TIM2_Init();
|
||||
@@ -136,13 +135,13 @@ int main(void)
|
||||
MODBUS_FirstInit();
|
||||
uint8_t uart_byte = 0;
|
||||
RS_Receive_IT(&hmodbus1, &MODBUS_MSG);
|
||||
Dallas_BusFirstInit(&htim1);
|
||||
// èíèöèàëèçàöèÿ ïî ïîðÿäêó íàéäåííûõ äàò÷èêîâ
|
||||
// Èíèöèàëèçàöèÿ ïî èíäåêñó (ïîðÿäêîâîìó íîìåðó íàéäåííîãî äàò÷èêà)
|
||||
Dallas_BusFirstInit(&htim1);
|
||||
// <EFBFBD><EFBFBD><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>
|
||||
// <EFBFBD><EFBFBD><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>)
|
||||
|
||||
for ( int i=0; i<hdallas.onewire->RomCnt;i++)
|
||||
{
|
||||
// Èíèöèàëèçàöèÿ ïî ROM-àäðåñó
|
||||
// <EFBFBD><EFBFBD><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;
|
||||
@@ -159,8 +158,45 @@ int main(void)
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
if( hmodbus1.pMessagePtr->Func_Code&ERR_VALUES_START)
|
||||
{
|
||||
static int pause_Alarm_led;
|
||||
while (1)
|
||||
{
|
||||
if (pause_Alarm_led>1000000)
|
||||
{
|
||||
GPIOC->ODR^=1<<13;
|
||||
pause_Alarm_led=0;
|
||||
|
||||
}
|
||||
pause_Alarm_led++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
for(int i=0;i<hdallas.onewire->RomCnt;i++)
|
||||
if(sens[i].isLost)
|
||||
{
|
||||
init_sens=1;
|
||||
}
|
||||
if (init_sens)
|
||||
{
|
||||
init_sens=0;
|
||||
//Dallas_BusFirstInit(&htim1);
|
||||
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]);
|
||||
|
||||
}
|
||||
}
|
||||
if (_debug_init||MB_DATA.Coils.init_param)
|
||||
{
|
||||
_debug_init=0;
|
||||
@@ -292,7 +328,7 @@ void SystemClock_Config(void)
|
||||
/* USER CODE BEGIN 4 */
|
||||
void iwdg_refresh(void)
|
||||
{
|
||||
IWDG->KR = 0xAAAA; // Ñáðîñèòü òàéìåð
|
||||
IWDG->KR = 0xAAAA; // <EFBFBD><EFBFBD><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)
|
||||
{
|
||||
@@ -382,7 +418,8 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
/* USER CODE BEGIN Callback 0 */
|
||||
|
||||
/* USER CODE END Callback 0 */
|
||||
if (htim->Instance == TIM3) {
|
||||
if (htim->Instance == TIM3)
|
||||
{
|
||||
HAL_IncTick();
|
||||
}
|
||||
/* USER CODE BEGIN Callback 1 */
|
||||
@@ -404,8 +441,7 @@ void Error_Handler(void)
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
|
||||
@@ -53,7 +53,7 @@ volatile uint32_t *config_reg = (OW_Pin_Numb < 8) ? &(OW->DataPort->CRL) : &(OW-
|
||||
}
|
||||
HAL_GPIO_Init(OW->DataPort, &GPIO_InitStruct);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +98,7 @@ uint8_t OneWire_Pin_Read(OneWire_t* OW)
|
||||
#else
|
||||
#ifdef LL_Driver
|
||||
return ((OW->DataPort->IDR & OW->DataPin) != 0x00U) ? 1 : 0;
|
||||
#else6
|
||||
#else
|
||||
return HAL_GPIO_ReadPin(OW->DataPort, OW->DataPin);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -57,24 +57,23 @@ void MX_RTC_Init(void)
|
||||
|
||||
/** Initialize RTC and set the Time and Date
|
||||
*/
|
||||
|
||||
// sTime.Hours = 0x0;
|
||||
// sTime.Minutes = 0x0;
|
||||
// sTime.Seconds = 0x0;
|
||||
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_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();
|
||||
// }
|
||||
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 */
|
||||
|
||||
@@ -44,7 +44,7 @@ void MX_SPI1_Init(void)
|
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
|
||||
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
|
||||
@@ -46,12 +46,15 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
|
||||
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 */
|
||||
@@ -71,12 +74,11 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
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
|
||||
*/
|
||||
* 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;
|
||||
|
||||
@@ -285,7 +285,7 @@ void TIM2_IRQHandler(void)
|
||||
/* USER CODE END TIM2_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim2);
|
||||
/* USER CODE BEGIN TIM2_IRQn 1 */
|
||||
RS_TIM_Handler(&hmodbus1);
|
||||
// RS_TIM_Handler(&hmodbus1);
|
||||
/* USER CODE END TIM2_IRQn 1 */
|
||||
}
|
||||
|
||||
@@ -313,7 +313,11 @@ static uint8_t first_in=1;
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN USART1_IRQn 0 */
|
||||
|
||||
if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_IDLE))
|
||||
{
|
||||
__HAL_UART_CLEAR_IDLEFLAG(&huart1);
|
||||
RS_TIM_Handler(&hmodbus1);
|
||||
}
|
||||
/* USER CODE END USART1_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart1);
|
||||
/* USER CODE BEGIN USART1_IRQn 1 */
|
||||
|
||||
@@ -36,7 +36,7 @@ void MX_USART1_UART_Init(void)
|
||||
/* USER CODE END USART1_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN USART1_Init 1 */
|
||||
|
||||
huart1.ReceptionType=HAL_UART_RECEPTION_TOIDLE;
|
||||
/* USER CODE END USART1_Init 1 */
|
||||
huart1.Instance = USART1;
|
||||
huart1.Init.BaudRate = 115200;
|
||||
|
||||
Reference in New Issue
Block a user