⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stm32f10x_adc.lst

📁 STM32利用正交编码器实现电机的控制
💻 LST
📖 第 1 页 / 共 5 页
字号:
    179            /* Configure ADCx: Dual mode and scan conversion mode */
    180            /* Set DUALMODE bits according to ADC_Mode value */
    181            /* Set SCAN bit according to ADC_ScanConvMode value */
    182            tmpreg1 |= (u32)(ADC_InitStruct->ADC_Mode | ((u32)ADC_InitStruct->ADC_ScanConvMode << 8));
    183            /* Write to ADCx CR1 */
    184            ADCx->CR1 = tmpreg1;
    185          
    186            /*---------------------------- ADCx CR2 Configuration -----------------*/
    187            /* Get the ADCx CR2 value */
    188            tmpreg1 = ADCx->CR2;
    189            /* Clear CONT, ALIGN and EXTTRIG bits */
    190            tmpreg1 &= CR2_CLEAR_Mask;
    191            /* Configure ADCx: external trigger event and continuous conversion mode */
    192            /* Set ALIGN bit according to ADC_DataAlign value */
    193            /* Set EXTTRIG bits according to ADC_ExternalTrigConv value */
    194            /* Set CONT bit according to ADC_ContinuousConvMode value */
    195            tmpreg1 |= (u32)(ADC_InitStruct->ADC_DataAlign | ADC_InitStruct->ADC_ExternalTrigConv |
    196                      ((u32)ADC_InitStruct->ADC_ContinuousConvMode << 1));
    197            /* Write to ADCx CR2 */
    198            ADCx->CR2 = tmpreg1;
    199          
    200            /*---------------------------- ADCx SQR1 Configuration -----------------*/
    201            /* Get the ADCx SQR1 value */
    202            tmpreg1 = ADCx->SQR1;
    203            /* Clear L bits */
    204            tmpreg1 &= SQR1_CLEAR_Mask;
    205            /* Configure ADCx: regular channel sequence length */
    206            /* Set L bits according to ADC_NbrOfChannel value */
    207            tmpreg2 |= (ADC_InitStruct->ADC_NbrOfChannel - 1);
    208            tmpreg1 |= ((u32)tmpreg2 << 20);
    209            /* Write to ADCx SQR1 */
    210            ADCx->SQR1 = tmpreg1;
    211          }
    212          
    213          /*******************************************************************************
    214          * Function Name  : ADC_StructInit
    215          * Description    : Fills each ADC_InitStruct member with its default value.
    216          * Input          : ADC_InitStruct : pointer to an ADC_InitTypeDef structure
    217          *                  which will be initialized.
    218          * Output         : None
    219          * Return         : None
    220          *******************************************************************************/
    221          void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct)
    222          {
    223            /* Reset ADC init structure parameters values */
    224            /* Initialize the ADC_Mode member */
    225            ADC_InitStruct->ADC_Mode = ADC_Mode_Independent;
    226          
    227            /* initialize the ADC_ScanConvMode member */
    228            ADC_InitStruct->ADC_ScanConvMode = DISABLE;
    229          
    230            /* Initialize the ADC_ContinuousConvMode member */
    231            ADC_InitStruct->ADC_ContinuousConvMode = DISABLE;
    232          
    233            /* Initialize the ADC_ExternalTrigConv member */
    234            ADC_InitStruct->ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
    235          
    236            /* Initialize the ADC_DataAlign member */
    237            ADC_InitStruct->ADC_DataAlign = ADC_DataAlign_Right;
    238          
    239            /* Initialize the ADC_NbrOfChannel member */
    240            ADC_InitStruct->ADC_NbrOfChannel = 1;
    241          }
    242          
    243          /*******************************************************************************
    244          * Function Name  : ADC_Cmd
    245          * Description    : Enables or disables the specified ADC peripheral.
    246          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    247          *                  - NewState: new state of the ADCx peripheral. This parameter
    248          *                    can be: ENABLE or DISABLE.
    249          * Output         : None
    250          * Return         : None
    251          *******************************************************************************/
    252          void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
    253          {
    254            /* Check the parameters */
    255            assert(IS_FUNCTIONAL_STATE(NewState));
    256          
    257            if (NewState != DISABLE)
    258            {
    259              /* Set the ADON bit to wake up the ADC from power down mode */
    260              ADCx->CR2 |= CR2_ADON_Set;
    261            }
    262            else
    263            {
    264              /* Disable the selected ADC peripheral */
    265              ADCx->CR2 &= CR2_ADON_Reset;
    266            }
    267          }
    268          
    269          /*******************************************************************************
    270          * Function Name  : ADC_DMACmd
    271          * Description    : Enables or disables the specified ADC DMA request.
    272          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    273          *                  - NewState: new state of the selected ADC DMA transfer.
    274          *                    This parameter can be: ENABLE or DISABLE.
    275          * Output         : None
    276          * Return         : None
    277          *******************************************************************************/
    278          void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState)
    279          {
    280            /* Check the parameters */
    281            assert(IS_FUNCTIONAL_STATE(NewState));
    282          
    283            if (NewState != DISABLE)
    284            {
    285              /* Enable the selected ADC DMA request */
    286              ADCx->CR2 |= CR2_DMA_Set;
    287            }
    288            else
    289            {
    290              /* Disable the selected ADC DMA request */
    291              ADCx->CR2 &= CR2_DMA_Reset;
    292            }
    293          }
    294          
    295          /*******************************************************************************
    296          * Function Name  : ADC_ITConfig
    297          * Description    : Enables or disables the specified ADC interrupts.
    298          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    299          *                  - ADC_IT: specifies the ADC interrupt sources to be enabled
    300          *                    or disabled. 
    301          *                    This parameter can be any combination of the following values:
    302          *                       - ADC_IT_EOC: End of conversion interrupt mask
    303          *                       - ADC_IT_AWD: Analog watchdog interrupt mask
    304          *                       - ADC_IT_JEOC: End of injected conversion interrupt mask
    305          *                  - NewState: new state of the specified ADC interrupts.
    306          *                    This parameter can be: ENABLE or DISABLE.
    307          * Output         : None
    308          * Return         : None
    309          *******************************************************************************/
    310          void ADC_ITConfig(ADC_TypeDef* ADCx, u16 ADC_IT, FunctionalState NewState)
    311          {
    312            u8 itmask = 0;
    313          
    314            /* Check the parameters */
    315            assert(IS_FUNCTIONAL_STATE(NewState));
    316            assert(IS_ADC_IT(ADC_IT));
    317          
    318            /* Get the ADC IT index */
    319            itmask = (u8)ADC_IT;
    320          
    321            if (NewState != DISABLE)
    322            {
    323              /* Enable the selected ADC interrupts */
    324              ADCx->CR1 |= itmask;
    325            }
    326            else
    327            {
    328              /* Disable the selected ADC interrupts */
    329              ADCx->CR1 &= (~(u32)itmask);
    330            }
    331          }
    332          
    333          /*******************************************************************************
    334          * Function Name  : ADC_ResetCalibration
    335          * Description    : Resets the selected ADC calibration registers.
    336          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    337          * Output         : None
    338          * Return         : None
    339          *******************************************************************************/
    340          void ADC_ResetCalibration(ADC_TypeDef* ADCx)
    341          {
    342            /* Resets the selected ADC calibartion registers */  
    343            ADCx->CR2 |= CR2_RSTCAL_Set;
    344          }
    345          
    346          /*******************************************************************************
    347          * Function Name  : ADC_GetResetCalibrationStatus
    348          * Description    : Gets the selected ADC reset calibration registers status.
    349          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    350          * Output         : None
    351          * Return         : The new state of ADC reset calibration registers (SET or RESET).
    352          *******************************************************************************/
    353          FlagStatus ADC_GetResetCalibrationStatus(ADC_TypeDef* ADCx)
    354          {
    355            FlagStatus bitstatus = RESET;
    356          
    357            /* Check the status of RSTCAL bit */
    358            if ((ADCx->CR2 & CR2_RSTCAL_Set) != (u16)RESET)
    359            {
    360              /* RSTCAL bit is set */
    361              bitstatus = SET;
    362            }
    363            else
    364            {
    365              /* RSTCAL bit is reset */
    366              bitstatus = RESET;
    367            }
    368            /* Return the RSTCAL bit status */
    369            return  bitstatus;
    370          }
    371          
    372          /*******************************************************************************
    373          * Function Name  : ADC_StartCalibration
    374          * Description    : Starts the selected ADC calibration process.
    375          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    376          * Output         : None
    377          * Return         : None
    378          *******************************************************************************/
    379          void ADC_StartCalibration(ADC_TypeDef* ADCx)
    380          {
    381            /* Enable the selected ADC calibration process */  
    382            ADCx->CR2 |= CR2_CAL_Set;
    383          }
    384          
    385          /*******************************************************************************
    386          * Function Name  : ADC_GetCalibrationStatus
    387          * Description    : Gets the selected ADC calibration status.
    388          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    389          * Output         : None
    390          * Return         : The new state of ADC calibration (SET or RESET).
    391          *******************************************************************************/
    392          FlagStatus ADC_GetCalibrationStatus(ADC_TypeDef* ADCx)
    393          {
    394            FlagStatus bitstatus = RESET;
    395          
    396            /* Check the status of CAL bit */
    397            if ((ADCx->CR2 & CR2_CAL_Set) != (u16)RESET)
    398            {
    399              /* CAL bit is set: calibration on going */
    400              bitstatus = SET;
    401            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -