中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 如何使用STM32的PVD對電源的電壓進行監(jiān)控

        如何使用STM32的PVD對電源的電壓進行監(jiān)控

        作者: 時間:2016-12-02 來源:網絡 收藏
        用戶在使用STM32時,可以利用其內部的PVD對VDD的電壓進行監(jiān)控,通過電源控制寄存器(PWR_CR)中的PLS[2:0]位來設定監(jiān)控的電壓值。
        PLS[2:0]位用于選擇PVD監(jiān)控電源的電壓閥值:
        000:2.2V
        001:2.3V
        010:2.4V
        011:2.5V
        100:2.6V
        101:2.7V
        110:2.8V
        111:2.9V
        在電源控制/狀態(tài)寄存器(PWR_CSR)中的PVDO標志用來表明VDD是高于還是低于PVD設定的電壓閥值。該事件連接到外部中斷的第16線,如果該中斷在外部中斷寄存器中被使能的,該事件就會產生中斷。當VDD下降到PVD閥值以下和(或)當VDD上升到PVD閥值之上時,根據外部中斷第16 線的上升/下降邊沿觸發(fā)設置,就會產生PVD中斷。這一特性可用于發(fā)現電壓出現異常時,執(zhí)行緊急關閉任務。
        下面是用于測試PVD的代碼:
        主程序的代碼:
        /* Includes ------------------------------------------------------------------*/
        #include "stm32f10x_lib.h"
        /* Private typedef -----------------------------------------------------------*/
        typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
        /* Private define ------------------------------------------------------------*/
        /* Private macro -------------------------------------------------------------*/
        /* Private variables ---------------------------------------------------------*/
        ErrorStatus HSEStartUpStatus;
        /* Private function prototypes -----------------------------------------------*/
        void RCC_Configuration(void);
        void GPIO_Configuration(void);
        void EXTI_Configuration(void);
        void NVIC_Configuration(void);
        /* Private functions ---------------------------------------------------------*/
        STM32 中文應用文檔
        /*****************************************************************************
        * Function Name : main
        * Description : Main program
        * Input : None
        * Output : None
        * Return : None
        ******************************************************************************/
        int main(void)
        {
        RCC_Configuration(); /* System Clocks Configuration */
        GPIO_Configuration(); /* Configure the GPIO ports */
        NVIC_Configuration(); /* NVIC configuration */
        EXTI_Configuration();
        PWR_PVDLevelConfig(PWR_PVDLevel_2V8);
        PWR_PVDCmd(ENABLE);
        while(1) {}
        }
        /*******************************************************************
        * Function Name : RCC_Configuration
        * Description : Configures the different system clocks.
        * Input : None
        * Output : None
        * Return : None
        ********************************************************************/
        void RCC_Configuration(void)
        {
        RCC_DeInit(); // RCC system reset(for debug purpose)
        RCC_HSEConfig(RCC_HSE_ON); // Enable HSE
        HSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is ready
        if(HSEStartUpStatus == SUCCESS) {
        RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLK
        RCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK
        RCC_PCLK1Config(RCC_HCLK_Div1); // PCLK1 = HCLK/2
        FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait state
        FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); // Enable Prefetch Buffer
        RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); // PLLCLK = 8MHz * 9 = 72 MHz
        RCC_PLLCmd(ENABLE); // Enable PLL
        while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {} // Wait till PLL is ready
        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Select PLL as system clock source
        while(RCC_GetSYSCLKSource() != 0x08) {} // Wait till PLL is used as system clock source
        }
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
        }
        STM32 中文應用文檔
        /****************************************************************
        * Function Name : GPIO_Configuration
        * Description : Configures the different GPIO ports.
        * Input : None
        * Output : None
        * Return : None
        ****************************************************************/
        void GPIO_Configuration(void)
        {
        GPIO_InitTypeDef GPIO_InitStructure;
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP;
        GPIO_Init(GPIOB, &GPIO_InitStructure); //GPIO B
        }
        /*******************************************************************
        * Function Name : EXTI_Configuration
        * Description : Configures .
        * Input : None
        * Output : None
        * Return : None
        ********************************************************************/
        void EXTI_Configuration(void)
        {
        EXTI_InitTypeDef EXTI_InitStructure;
        EXTI_DeInit();
        EXTI_StructInit(&EXTI_InitStructure);
        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 EXTI Line16 to generate an interrupt
        }
        /***************************************************************************
        * Function Name : NVIC_Configuration
        * Description : Configures Vector Table base location.
        * Input : None
        * Output : None
        * Return : None
        **************************************************************************/
        void NVIC_Configuration(void)
        {
        NVIC_InitTypeDef NVIC_InitStructure;
        #ifdef VECT_TAB_RAM
        /* Set the Vector Table base location at 0x20000000 */
        NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
        #else /* VECT_TAB_FLASH */
        /* Set the Vector Table base location at 0x08000000 */
        NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
        #endif
        STM32 中文應用文檔
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); // Configure one bit for preemption priority
        NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQChannel;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure); // Enable the PVD Interrupt
        }
        中斷程序:
        /**************************************************************************
        * Function Name : PVD_IRQHandler
        * Description : This function handles PVD interrupt request.
        * Input : None
        * Output : None
        * Return : None
        ***************************************************************************/
        void PVD_IRQHandler(void)
        {
        if (PWR_GetFlagStatus(PWR_FLAG_PVDO))
        GPIO_WriteBit(GPIOB, 1 << 5, Bit_SET);
        else
        GPIO_WriteBit(GPIOB, 1 << 5, Bit_RESET);
        }
        注:在void EXTI_Configuration(void)中,對于EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; 中的初始化值,根據你的需要進行修改,具體細節(jié)如下:
        EXTI_Trigger_Rising --- 表示電壓從高電壓下降到低于設定的電壓閥值產生中斷;
        EXTI_Trigger_Falling --- 表示電壓從低電壓上升到高于設定的電壓閥值產生中斷;
        EXTI_Trigger_Rising_Falling --- 表示電壓從高電壓下降到低于設定的電壓閥值、或從低電壓上升到高于設定的電壓閥值產生中斷。


        關鍵詞: STM32PVD監(jiān)

        評論


        技術專區(qū)

        關閉