Chinaunix首页 | 论坛 | 博客
  • 博客访问: 132363
  • 博文数量: 64
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-26 18:44
文章分类

全部博文(64)

文章存档

2014年(64)

我的朋友

分类: C/C++

2014-04-26 19:05:37

原文地址:STM32之PVD电压检测 作者:

如果VDD或者VDDA电压高于或低于PVD设定阈值都产生中断,表现为每中断一次,LED1就亮变灭或者灭变亮。

点击(此处)折叠或打开

  1. /********************************************************************************
  2.   * @file PWR/PVD/main.c
  3.   * @author MCD Application Team
  4.   * @version V3.4.0
  5.   * @date 10/15/2010
  6.   * @brief Main program body.
  7.   ******************************************************************************/
  8. /* Includes ------------------------------------------------------------------*/
  9. #include "stm32f10x.h"
  10. #include "stm32_eval.h"

  11. void EXTI_Configuration(void);
  12. void NVIC_Configuration(void);

  13. /**
  14.   * @brief Main program.
  15.   * @param None
  16.   * @retval None
  17.   */
  18. int main(void)
  19. {
  20.   /*!< At this stage the microcontroller clock setting is already configured,
  21.        this is done through SystemInit() function which is called from startup
  22.        file (startup_stm32f10x_xx.s) before to branch to application main.
  23.        To reconfigure the default setting of SystemInit() function, refer to
  24.        system_stm32f10x.c file
  25.      */
  26.   /* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */
  27.   STM_EVAL_LEDInit(LED1);
  28.   
  29.   GPIO_SetBits(GPIOC, GPIO_Pin_7);

  30.   /* Enable PWR and BKP clock */
  31.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);//电源管理部分时钟开启

  32.   /* Configure EXTI Line to generate an interrupt on falling edge */
  33.   EXTI_Configuration();

  34.   /* NVIC configuration */
  35.   NVIC_Configuration();
  36.  
  37.   /* Configure the PVD Level to 2.9V */
  38.   PWR_PVDLevelConfig(PWR_PVDLevel_2V9);// 设定监控阀值

  39.   /* Enable the PVD Output */
  40.   PWR_PVDCmd(ENABLE);// 使能PVD
  41.   
  42.   while (1)
  43.   {
  44.   }
  45. }

  46. /**
  47.   * @brief Configures EXTI Lines.
  48.   * @param None
  49.   * @retval None
  50.   */
  51. void EXTI_Configuration(void)
  52. {
  53.   EXTI_InitTypeDef EXTI_InitStructure;

  54.   /* Configure EXTI Line16(PVD Output) to generate an interrupt on rising and
  55.      falling edges */
  56.   EXTI_ClearITPendingBit(EXTI_Line16);
  57.   EXTI_InitStructure.EXTI_Line = EXTI_Line16;// PVD连接到中断线16上
  58.   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//使用中断模式
  59.   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//电压上升或下降越过设定阀值时都产生中断。
  60.   EXTI_InitStructure.EXTI_LineCmd = ENABLE;// 使能中断线
  61.   EXTI_Init(&EXTI_InitStructure);// 初始
  62. }

  63. /**
  64.   * @brief Configures NVIC and Vector Table base location.
  65.   * @param None
  66.   * @retval None
  67.   */
  68. void NVIC_Configuration(void)
  69. {
  70.   NVIC_InitTypeDef NVIC_InitStructure;
  71.   
  72.   /* Configure one bit for preemption priority */
  73.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//中断优先级配置
  74.   
  75.   /* Enable the PVD Interrupt */ //设置PVD中断
  76.   NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQn;
  77.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  78.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  79.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  80.   NVIC_Init(&NVIC_InitStructure);
  81. }
  82. /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
注意:GPIO驱动LED模式为GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;还是推挽输出。
中断处理函数:
点击(此处)折叠或打开
  1. void PVD_IRQHandler(void)
  2. {
  3. if(EXTI_GetITStatus(EXTI_Line16) != RESET)
  4. {
  5. /* LED1翻转 */
  6. STM_EVAL_LEDToggle(LED1);
  7. /* Clear the Key Button EXTI line pending bit */
  8. EXTI_ClearITPendingBit(EXTI_Line16);
  9. }
  10. }

阅读(953) | 评论(0) | 转发(0) |
0

上一篇:STM32文档学习

下一篇:STM32电源管理器

给主人留下些什么吧!~~