borrow1988 发表于 2018-8-31 10:32:27

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

本帖最后由 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);
}

      

eric2013 发表于 2018-8-31 10:56:20

这个不是官方的标准配置吗,测试不行吗

/**
******************************************************************************
* @file    PWR/PWR_PVD/main.c
* @authorMCD Application Team
* @version V1.7.0
* @date    22-April-2016
* @brief   Main program body
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
*      http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/

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

/** @addtogroup STM32F4xx_StdPeriph_Examples
* @{
*/

/** @addtogroup PWR_PVD
* @{
*/

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
__IO uint32_t uwCounter = 0;

/* Private function prototypes -----------------------------------------------*/
void PVD_Config(void);

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

/**
* @briefMain program
* @paramNone
* @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
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s)
       before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
   */   
      
/* Initialize LEDs on EVAL board */
STM_EVAL_LEDInit(LED1);
STM_EVAL_LEDInit(LED2);

/* Configure the PVD */
PVD_Config();

while (1)
{
    /* Toggle LED2 */
    STM_EVAL_LEDToggle(LED2);

    /* Inserted Delay */
    for(uwCounter = 0; uwCounter < 0x5FFFF; uwCounter++);
}
}

/**
* @briefConfigures the PVD resources.
* @paramNone
* @retval None
*/
void PVD_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;

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

/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

/* Enable the PVD Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
      
/* Configure EXTI Line16(PVD Output) to generate an interrupt on rising and
   falling edges */
EXTI_ClearITPendingBit(EXTI_Line16);
EXTI_InitStructure.EXTI_Line = EXTI_Line16;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);

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

/* Enable the PVD Output */
PWR_PVDCmd(ENABLE);
}

#ifdefUSE_FULL_ASSERT

/**
* @briefReports the name of the source file and the source line number
*         where the assert_param error has occurred.
* @paramfile: pointer to the source file name
* @paramline: 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 STMicroelectronics *****END OF FILE****/



中断:

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

/**
* @briefThis function handles the PVD Output interrupt request.
* @paramNone
* @retval None
*/
void PVD_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line16) != RESET)
{
    /* Toggle LED1 */
    STM_EVAL_LEDToggle(LED1);

    /* Clear the Key Button EXTI line pending bit */
    EXTI_ClearITPendingBit(EXTI_Line16);
}
}

borrow1988 发表于 2018-8-31 11:21:21

eric2013 发表于 2018-8-31 10:56
这个不是官方的标准配置吗,测试不行吗




EXTI_Trigger_Rising_Falling 改为EXTI_Trigger_Falling 不行。。。

borrow1988 发表于 2018-9-4 09:34:16

eric2013 发表于 2018-8-31 10:56
这个不是官方的标准配置吗,测试不行吗




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

流型 发表于 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 bits.
if((PWR_GetFlagStatus(PWR_FLAG_PVDO) == RESET)) // PVDO = 0, VDD is higher than the PVD threshold selected with the PLS bits.
页: [1]
查看完整版本: ...请教下PVD不进中断,查询方式可以...