2578|5

2

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

关于stm32 EXIT编写步骤,大神们多多指教,求最简 [复制链接]

关于stm32 EXIT编写步骤,大神们多多指教,求最简
此帖出自stm32/stm8论坛

最新回复

/**   ******************************************************************************   * @file    EXTI/EXTI_Config/main.c   * @author  MCD Application Team   * @version V3.5.0   * @date    08-April-2011   * @brief   Main program body   ******************************************************************************   * @attention   *   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.   *   * © COPYRIGHT 2011 STMicroelectronics   ******************************************************************************   */ /* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h" #include "stm32_eval.h" /** @addtogroup STM32F10x_StdPeriph_Examples   * @{   */ /** @addtogroup EXTI_Config   * @{   */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ EXTI_InitTypeDef   EXTI_InitStructure; GPIO_InitTypeDef   GPIO_InitStructure; NVIC_InitTypeDef   NVIC_InitStructure; /* Private function prototypes -----------------------------------------------*/ void EXTI0_Config(void); void EXTI9_5_Config(void); /* Private functions ---------------------------------------------------------*/ /**   * @brief  Main program.   * @param  None   * @retval None   */ int main(void) {   /*!< At this stage the microcontroller clock setting is already configured,        this is done through SystemInit() function which is called from startup        file (startup_stm32f10x_xx.s) before to branch to application main.        To reconfigure the default setting of SystemInit() function, refer to        system_stm32f10x.c file      */                  /* Initialize LED1 and Key Button mounted on STM3210X-EVAL board */         STM_EVAL_LEDInit(LED1);   STM_EVAL_LEDInit(LED2);      /* Configure PA.00 in interrupt mode */   EXTI0_Config();   /* Configure PB.09 or PG.08 in interrupt mode */   EXTI9_5_Config();   /* Generate software interrupt: simulate a falling edge applied on EXTI0 line */   EXTI_GenerateSWInterrupt(EXTI_Line0);             while (1)   {   } } /**   * @brief  Configure PA.00 in interrupt mode   * @param  None   * @retval None   */ void EXTI0_Config(void) {   /* Enable GPIOA clock */   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);      /* Configure PA.00 pin as input floating */   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   GPIO_Init(GPIOA, &GPIO_InitStructure);   /* Enable AFIO clock */   RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);   /* Connect EXTI0 Line to PA.00 pin */   GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);   /* Configure EXTI0 line */   EXTI_InitStructure.EXTI_Line = EXTI_Line0;   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;     EXTI_InitStructure.EXTI_LineCmd = ENABLE;   EXTI_Init(&EXTI_InitStructure);   /* Enable and set EXTI0 Interrupt to the lowest priority */   NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;   NVIC_Init(&NVIC_InitStructure); } /**   * @brief  Configure PB.09 or PG.08 in interrupt mode   * @param  None   * @retval None   */ void EXTI9_5_Config(void) { #if defined (STM32F10X_HD_VL) || defined (STM32F10X_HD) || defined (STM32F10X_XL)   /* Enable GPIOG clock */   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE);   /* Configure PG.08 pin as input floating */   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   GPIO_Init(GPIOG, &GPIO_InitStructure);   /* Enable AFIO clock */   RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);   /* Connect EXTI8 Line to PG.08 pin */   GPIO_EXTILineConfig(GPIO_PortSourceGPIOG, GPIO_PinSource8);   /* Configure EXTI8 line */   EXTI_InitStructure.EXTI_Line = EXTI_Line8;   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;   EXTI_InitStructure.EXTI_LineCmd = ENABLE;   EXTI_Init(&EXTI_InitStructure);   /* Enable and set EXTI9_5 Interrupt to the lowest priority */   NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;   NVIC_Init(&NVIC_InitStructure); #else   /* Enable GPIOB clock */   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);   /* Configure PB.09 pin as input floating */   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   GPIO_Init(GPIOB, &GPIO_InitStructure);   /* Enable AFIO clock */   RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);   /* Connect EXTI9 Line to PB.09 pin */   GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);   /* Configure EXTI9 line */   EXTI_InitStructure.EXTI_Line = EXTI_Line9;   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;   EXTI_InitStructure.EXTI_LineCmd = ENABLE;   EXTI_Init(&EXTI_InitStructure);   /* Enable and set EXTI9_5 Interrupt to the lowest priority */   NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;   NVIC_Init(&NVIC_InitStructure); #endif } #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 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) */   /* Infinite loop */   while (1)   {   } } #endif /**   * @}   */ /**   * @}   */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/  详情 回复 发表于 2012-12-6 11:08
点赞 关注
 

回复
举报

4008

帖子

0

TA的资源

版主

沙发
 
什么是EXIT?
此帖出自stm32/stm8论坛
 
 

回复

6105

帖子

4

TA的资源

版主

板凳
 
就是那个GPIO的中断。
此帖出自stm32/stm8论坛
 
 

回复

6105

帖子

4

TA的资源

版主

4
 
当然是要配GPIO的时钟,要配置EXIT对应哪个IO,还有EXIT的一些东西还有中断。
此帖出自stm32/stm8论坛
 
 
 

回复

6105

帖子

4

TA的资源

版主

5
 
具体不记得。
此帖出自stm32/stm8论坛
 
 
 

回复

4008

帖子

0

TA的资源

版主

6
 
/**
  ******************************************************************************
  * @file    EXTI/EXTI_Config/main.c
  * @author  MCD Application Team
  * @version V3.5.0
  * @date    08-April-2011
  * @brief   Main program body
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  *

© COPYRIGHT 2011 STMicroelectronics


  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32_eval.h"

/** @addtogroup STM32F10x_StdPeriph_Examples
  * @{
  */

/** @addtogroup EXTI_Config
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
EXTI_InitTypeDef   EXTI_InitStructure;
GPIO_InitTypeDef   GPIO_InitStructure;
NVIC_InitTypeDef   NVIC_InitStructure;

/* Private function prototypes -----------------------------------------------*/
void EXTI0_Config(void);
void EXTI9_5_Config(void);

/* Private functions ---------------------------------------------------------*/

/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     
         
  /* Initialize LED1 and Key Button mounted on STM3210X-EVAL board */      
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  
  /* Configure PA.00 in interrupt mode */
  EXTI0_Config();

  /* Configure PB.09 or PG.08 in interrupt mode */
  EXTI9_5_Config();

  /* Generate software interrupt: simulate a falling edge applied on EXTI0 line */
  EXTI_GenerateSWInterrupt(EXTI_Line0);
         
  while (1)
  {
  }
}

/**
  * @brief  Configure PA.00 in interrupt mode
  * @param  None
  * @retval None
  */
void EXTI0_Config(void)
{
  /* Enable GPIOA clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  
  /* Configure PA.00 pin as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Enable AFIO clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

  /* Connect EXTI0 Line to PA.00 pin */
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);

  /* Configure EXTI0 line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line0;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Enable and set EXTI0 Interrupt to the lowest priority */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

/**
  * @brief  Configure PB.09 or PG.08 in interrupt mode
  * @param  None
  * @retval None
  */
void EXTI9_5_Config(void)
{
#if defined (STM32F10X_HD_VL) || defined (STM32F10X_HD) || defined (STM32F10X_XL)
  /* Enable GPIOG clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE);

  /* Configure PG.08 pin as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOG, &GPIO_InitStructure);

  /* Enable AFIO clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  /* Connect EXTI8 Line to PG.08 pin */
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOG, GPIO_PinSource8);

  /* Configure EXTI8 line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line8;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Enable and set EXTI9_5 Interrupt to the lowest priority */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);
#else
  /* Enable GPIOB clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

  /* Configure PB.09 pin as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Enable AFIO clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  /* Connect EXTI9 Line to PB.09 pin */
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);

  /* Configure EXTI9 line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line9;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Enable and set EXTI9_5 Interrupt to the lowest priority */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);
#endif
}

#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 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) */

  /* Infinite loop */
  while (1)
  {
  }
}

#endif

/**
  * @}
  */

/**
  * @}
  */

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
此帖出自stm32/stm8论坛
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/9 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表