用cube写的独立看门狗,无反应

2019-07-20 09:23发布

#include "stm32f7xx_hal.h"
#include "stm32f7xx_it.h"
#include "delay.h"
#include "sys.h"
/* USER CODE BEGIN Includes */

#define WK_UP HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)

#define LED0(n) (n?HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_SET):HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_RESET))
#define LED0_Toggle (HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0))

/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/

IWDG_HandleTypeDef hiwdg; //¶àᢿ′ÃÅ1·¾ä±ú
UART_HandleTypeDef huart1;

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);
static void MX_IWDG_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_GPIO_Init(void);
void IWDG_Feed(void)
{   
    HAL_IWDG_Refresh(&hiwdg); //ÖØ×°ÔØ
}
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/
Cache_Enable();
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();
  delay_init(216);
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  delay_ms(200);  
  MX_IWDG_Init();

  /* USER CODE BEGIN 2 */
   /* USER CODE END 2 */
  LED0(0);                                       
  /* Infinite loop */

  /* USER CODE BEGIN WHILE */
  while (1)
  {         

    if(WK_UP==1)          //èç1ûWK_UP°′Ï£¬Î11·
       {
           IWDG_Feed();                            //Î11·
      }
       delay_ms(10);
//   printf("ÕyμãÔ-×ó@ALIENTEK ");
//         delay_ms(1000);
  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
static void MX_IWDG_Init(void)
{

  hiwdg.Instance = IWDG;
  hiwdg.Init.Prescaler = IWDG_PRESCALER_64;
  hiwdg.Init.Reload =500;
  hiwdg.Init.Window = 0xfff;
  HAL_IWDG_Init(&hiwdg);  

}


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。