这是HK32F1新增的寄存器,就是官方的库里没有才来问的,不过已经写好了,有需要的可以看下
/*********ADC时钟 分频因子 *************************************************/
#define RCC_PCLK2_Div10 ((uint32_t)0x00100000)
#define RCC_PCLK2_Div12 ((uint32_t)0x00200000)
#define RCC_PCLK2_Div14 ((uint32_t)0x00300000)
#define RCC_PCLK2_Div16 ((uint32_t)0x00400000)
#define RCC_PCLK2_Div20 ((uint32_t)0x00500000)
#define IS_RCC_ADC1_CLK(ADCCLK) (((ADCCLK) == RCC_PCLK2_Div10) || ((ADCCLK) == RCC_PCLK2_Div12) || \
((ADCCLK) == RCC_PCLK2_Div14) || ((ADCCLK) == RCC_PCLK2_Div16) || \
((ADCCLK) == RCC_PCLK2_Div20))
/*******************************************************************************
* Function Name : ADC1_CLK_DIV
* Description : ADC1时钟分频 ADC时钟不能超过14M,120/10=12M
* Input : * [url=home.php?mod=space&uid=2817080]@ARG[/url] RCC_PCLK2_Div2: ADC clock = PCLK2/2
* @arg RCC_PCLK2_Div4: ADC clock = PCLK2/4
* @arg RCC_PCLK2_Div6: ADC clock = PCLK2/6
* @arg RCC_PCLK2_Div8: ADC clock = PCLK2/8
* @arg RCC_PCLK2_Div10: ADC clock = PCLK2/10
* @arg RCC_PCLK2_Div12: ADC clock = PCLK2/12
* @arg RCC_PCLK2_Div14: ADC clock = PCLK2/14
* @arg RCC_PCLK2_Div16: ADC clock = PCLK2/16
* @arg RCC_PCLK2_Div20: ADC clock = PCLK2/20
* Output : None
* Return : None
*******************************************************************************/
void ADC1_CLK_DIV(uint32_t RCC_PCLK2)
{
//自定义RCC寄存器
typedef struct
{
__IO uint32_t CR;
__IO uint32_t CFGR;
__IO uint32_t CIR;
__IO uint32_t APB2RSTR;
__IO uint32_t APB1RSTR;
__IO uint32_t AHBENR;
__IO uint32_t APB2ENR;
__IO uint32_t APB1ENR;
__IO uint32_t BDCR; //0x20
__IO uint32_t CSR; //0x24
__IO uint32_t reserved1;//0x28
__IO uint32_t CFGR2; //0x2C HK32F103新增
__IO uint32_t CFGR3; //0x30 HK32F103新增
} RCC_Register;
__IO RCC_Register* rcc_register =(RCC_Register*) RCC;
//2-8分频
if(IS_RCC_ADCCLK(RCC_PCLK2))
{
RCC_ADCCLKConfig(RCC_PCLK2);
}
//10-20分频
if(IS_RCC_ADC1_CLK(RCC_PCLK2))
{
//写CFGR3的ADC1SW位配置ADC1时钟分频
rcc_register->CFGR3 &= 0xFF8FFFFF;//清空位22:20 ADC1SW
rcc_register->CFGR3 |= RCC_PCLK2;//22:20 ADC1SW置RCC_PCLK2
}
}
|