《STM32笔记寄存器设置 C.docx》由会员分享,可在线阅读,更多相关《STM32笔记寄存器设置 C.docx(3页珍藏版)》请在三一办公上搜索。
1、STM32笔记 寄存器设置 C1、关于管脚重映射的问题 PA11,PA12为CAN默认管脚 void GPIO_Configuration(void) GPIO_InitTypeDef GPIO_InitStructure; / CAN IO configuration -/ / Enable GPIOA & AFEN(Alternate Function) clock / RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); /GPIO_PinRemapConfig(GPIO_Remap2_CA
2、N, ENABLE);/ Remap1 of CAN /* Configure PC.06, PC.07, PC.08 and PC.09 as Output push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_Init
3、Structure); /* Configure CAN pin: RX */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure CAN pin: TX */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPI
4、OA, &GPIO_InitStructure); 2、关于CAN的时钟配置问题 void RCC_Configuration(void) /* RCC system reset(for debug purpose) */ RCC_DeInit; /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp; if(HSEStartUpStatus = SUCCESS) /* Enable Prefetch Buffer */ F
5、LASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div4); /* Select HSE as system clock source */ / RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); /* Wait
6、till HSE is used as system clock source */ / while(RCC_GetSYSCLKSource != 0x04) /* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) = RESET) /* Select PLL as s
7、ystem clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource != 0x08) /* GPIOA and GPIOC clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE); /* CAN Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);