stm32外设初始化和设置过程

1.主应用文件中声明PPP_InitTypeDef结构体变量。

 例:GPIO_InitTypeDef GPIO_InitStructure;

2.为定义的结构体变量设置需要的值。

设置变量中所有的值:PPP_InitStructure.member1 = value1;PPP_InitStructure.member2 = value2;...

                     OR:            定义时直接赋值:PPP_InitTypeDef PPP_InitStructure = {value1,value2,value3....};

设置变量中部分值:PPP_StructInit(&PPP_InitStructure);//先对结构体变量进行初始化

                                    PPP_InitStructure.member1 = value1;PPP_InitStructure.member2 = value2;...

3.在设置一个外设前,必须调用一下一个函数来使能它的时钟。

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_PPPx,ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PPPx,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_PPPx,ENABLE);

4.调用PPP_Init(PPP,&PPP_InitStructure)进行外设初始化。//PPP_DeInit()功能和PPP_Init(PPP)相反,将寄存器复位为缺省值。

5.PPP_Cmd(PPP,ENABLE);将外设使能。

猜你喜欢

转载自blog.csdn.net/qinrenzhi/article/details/81707719