硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1963|回复: 4
收起左侧

...请教下PVD不进中断,查询方式可以...

[复制链接]

27

主题

91

回帖

172

积分

初级会员

积分
172
发表于 2018-8-31 10:32:27 | 显示全部楼层 |阅读模式
本帖最后由 borrow1988 于 2018-8-31 10:35 编辑


...请教大家下,PVD使用中断方式无法进中断,但是查询可以

以下是配置,其中NVCI为1组:NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
void PWR_PVD_Init(void)
{
        NVIC_InitTypeDef NVIC_InitStructure;
        EXTI_InitTypeDef EXTI_InitStructure;
        
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);//使能PWR时钟
        
        NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQn;                         //使能PVD所在的外部中断通道
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;//抢占优先级1
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;                 //子优先级0
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                  //使能外部中断通道
        NVIC_Init(&NVIC_InitStructure);
               
        
//        EXTI_StructInit(&EXTI_InitStructure);
        EXTI_InitStructure.EXTI_Line = EXTI_Line16;                         //PVD连接到中断线16上
        EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;         //使用中断模式
        EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;        //电压低于阀值时产生中断
        EXTI_InitStructure.EXTI_LineCmd = ENABLE;                                //使能中断线
        EXTI_Init(&EXTI_InitStructure);         
        
        PWR_PVDLevelConfig(PWR_PVDLevel_2V5);//设定监控阀值   注意和F1的区别        F1的电压等级就更直观        PWR_PVDLevel_2V8
        PWR_PVDCmd(ENABLE);//使能PVD                 
}


void PVD_IRQHandler(void)
{
        printf("\r\n PVD ISR \r\n");
        if(EXTI_GetITStatus(PWR_FLAG_PVDO)!=RESET)
        {
           GPIO_ResetBits(GPIOA,GPIO_Pin_1);
            //掉电了
                printf("\r\n PVD\r\n");
        }
        EXTI_ClearITPendingBit(EXTI_Line16);
}

        

回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106660
QQ
发表于 2018-8-31 10:56:20 | 显示全部楼层
这个不是官方的标准配置吗,测试不行吗

  1. /**
  2.   ******************************************************************************
  3.   * @file    PWR/PWR_PVD/main.c
  4.   * @author  MCD Application Team
  5.   * @version V1.7.0
  6.   * @date    22-April-2016
  7.   * @brief   Main program body
  8.   ******************************************************************************
  9.   * @attention
  10.   *
  11.   * <h2><center>&#169; COPYRIGHT 2016 STMicroelectronics</center></h2>
  12.   *
  13.   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14.   * You may not use this file except in compliance with the License.
  15.   * You may obtain a copy of the License at:
  16.   *
  17.   *        http://www.st.com/software_license_agreement_liberty_v2
  18.   *
  19.   * Unless required by applicable law or agreed to in writing, software
  20.   * distributed under the License is distributed on an "AS IS" BASIS,
  21.   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22.   * See the License for the specific language governing permissions and
  23.   * limitations under the License.
  24.   *
  25.   ******************************************************************************
  26.   */

  27. /* Includes ------------------------------------------------------------------*/
  28. #include "main.h"

  29. /** @addtogroup STM32F4xx_StdPeriph_Examples
  30.   * @{
  31.   */

  32. /** @addtogroup PWR_PVD
  33.   * @{
  34.   */

  35. /* Private typedef -----------------------------------------------------------*/
  36. /* Private define ------------------------------------------------------------*/
  37. /* Private macro -------------------------------------------------------------*/
  38. /* Private variables ---------------------------------------------------------*/
  39. __IO uint32_t uwCounter = 0;

  40. /* Private function prototypes -----------------------------------------------*/
  41. void PVD_Config(void);

  42. /* Private functions ---------------------------------------------------------*/

  43. /**
  44.   * @brief  Main program
  45.   * @param  None
  46.   * @retval None
  47.   */
  48. int main(void)
  49. {
  50.   /*!< At this stage the microcontroller clock setting is already configured,
  51.        this is done through SystemInit() function which is called from startup
  52.        files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s)
  53.        before to branch to application main.
  54.        To reconfigure the default setting of SystemInit() function, refer to
  55.        system_stm32f4xx.c file
  56.      */     
  57.       
  58.   /* Initialize LEDs on EVAL board */
  59.   STM_EVAL_LEDInit(LED1);
  60.   STM_EVAL_LEDInit(LED2);
  61.   
  62.   /* Configure the PVD */
  63.   PVD_Config();
  64.   
  65.   while (1)
  66.   {
  67.     /* Toggle LED2 */
  68.     STM_EVAL_LEDToggle(LED2);

  69.     /* Inserted Delay */
  70.     for(uwCounter = 0; uwCounter < 0x5FFFF; uwCounter++);
  71.   }
  72. }

  73. /**
  74.   * @brief  Configures the PVD resources.
  75.   * @param  None
  76.   * @retval None
  77.   */
  78. void PVD_Config(void)
  79. {
  80.   NVIC_InitTypeDef NVIC_InitStructure;
  81.   EXTI_InitTypeDef EXTI_InitStructure;

  82.   /* Enable PWR clock */
  83.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  84.   /* Configure one bit for preemption priority */
  85.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  86.   
  87.   /* Enable the PVD Interrupt */
  88.   NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQn;
  89.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  90.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  91.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  92.   NVIC_Init(&NVIC_InitStructure);
  93.       
  94.   /* Configure EXTI Line16(PVD Output) to generate an interrupt on rising and
  95.      falling edges */
  96.   EXTI_ClearITPendingBit(EXTI_Line16);
  97.   EXTI_InitStructure.EXTI_Line = EXTI_Line16;
  98.   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  99.   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
  100.   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  101.   EXTI_Init(&EXTI_InitStructure);

  102.   /* Configure the PVD Level to 3 (PVD detection level set to 2.5V, refer to the
  103.       electrical characteristics of you device datasheet for more details) */
  104.   PWR_PVDLevelConfig(PWR_PVDLevel_3);

  105.   /* Enable the PVD Output */
  106.   PWR_PVDCmd(ENABLE);
  107. }

  108. #ifdef  USE_FULL_ASSERT

  109. /**
  110.   * @brief  Reports the name of the source file and the source line number
  111.   *         where the assert_param error has occurred.
  112.   * @param  file: pointer to the source file name
  113.   * @param  line: assert_param error line source number
  114.   * @retval None
  115.   */
  116. void assert_failed(uint8_t* file, uint32_t line)
  117. {
  118.   /* User can add his own implementation to report the file name and line number,
  119.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  120.   /* Infinite loop */
  121.   while (1)
  122.   {
  123.   }
  124. }
  125. #endif

  126. /**
  127.   * @}
  128.   */

  129. /**
  130.   * @}
  131.   */

  132. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码



中断:

  1. /******************************************************************************/
  2. /*                 STM32F4xx Peripherals Interrupt Handlers                   */
  3. /*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
  4. /*  available peripheral interrupt handler's name please refer to the startup */
  5. /*  file (startup_stm32f40xx.s.startup_stm32f427x.s).                         */
  6. /******************************************************************************/

  7. /**
  8.   * @brief  This function handles the PVD Output interrupt request.
  9.   * @param  None
  10.   * @retval None
  11.   */
  12. void PVD_IRQHandler(void)
  13. {
  14.   if(EXTI_GetITStatus(EXTI_Line16) != RESET)
  15.   {
  16.     /* Toggle LED1 */
  17.     STM_EVAL_LEDToggle(LED1);

  18.     /* Clear the Key Button EXTI line pending bit */
  19.     EXTI_ClearITPendingBit(EXTI_Line16);
  20.   }
  21. }
复制代码


回复

使用道具 举报

27

主题

91

回帖

172

积分

初级会员

积分
172
 楼主| 发表于 2018-8-31 11:21:21 | 显示全部楼层
eric2013 发表于 2018-8-31 10:56
这个不是官方的标准配置吗,测试不行吗

EXTI_Trigger_Rising_Falling 改为EXTI_Trigger_Falling 不行。。。
回复

使用道具 举报

27

主题

91

回帖

172

积分

初级会员

积分
172
 楼主| 发表于 2018-9-4 09:34:16 | 显示全部楼层
eric2013 发表于 2018-8-31 10:56
这个不是官方的标准配置吗,测试不行吗

如果加RTOS 比如UCOS,掉电进不去,是不是因为OS调度时,把中断关了
回复

使用道具 举报

5

主题

81

回帖

96

积分

初级会员

积分
96
发表于 2023-5-22 16:29:33 | 显示全部楼层
可能存在有两个问题:
(1)EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;        //电压低于阀值时产生中断,这个应该理解反了,根据手册中PVD示意图的描述,掉电检测应该用EXTI_Trigger_Rising触发,上电用EXTI_Trigger_Falling。
(2)中断函数里这个EXTI_GetITStatus(PWR_FLAG_PVDO)的值也有讲究,根据参考手册中的寄存器描述
if(PWR_GetFlagStatus(PWR_FLAG_PVDO) == SET) , PVDO = 1, VDD is lower than the PVD threshold selected with the PLS[2:0] bits.
if((PWR_GetFlagStatus(PWR_FLAG_PVDO) == RESET)) // PVDO = 0, VDD is higher than the PVD threshold selected with the PLS[2:0] bits.
1.png
回复

使用道具 举报

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

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-4-29 06:45 , Processed in 0.177686 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表