完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
/****系统外设时钟设置*** void Clock_Peripheral_Init() { RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);// RCC_APB1PeriphClockCmd(RCC_APB1Periph_tiM2,ENABLE);// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);// } /****I/O初始化***** void GPIO_Configuration() { GPIO_InitTypeDef GPIO_InitStructure; //GPIOA GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_2; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure);// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_3; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure);// } /***UART1初始化***** void UART1_Configuration() { USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate = 19200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; USART_Init(USART1, &USART_InitStructure); USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//ʹÄܽÓÊÕÖÐ¶Ï USART_Cmd(USART1, ENABLE);//´®¿Ú1ÍâÉèʹÄÜ } /***UART2初始化**** void UART2_Configuration() { USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate = 4800; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_Even; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; USART_Init(USART2, &USART_InitStructure); USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); USART_Cmd(USART2, ENABLE); } /***定时器2配置**** void TIM2_Configuration(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_DeInit(TIM2); //³õʼ»¯ÎªÈ±Ê¡Öµ TIM_TimeBaseStructure.TIM_Period=1000; TIM_TimeBaseStructure.TIM_Prescaler= (72 - 1); TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_ClearFlag(TIM2, TIM_FLAG_Update); TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE); TIM_Cmd(TIM2, ENABLE); } /****优先级***** void NVIC_Configuration() { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;//TIME2 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;//ÏÈÕ¼ÓÅÏȼ¶ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
|
|
相关推荐
1个回答
|
|
设置有问题
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
STM32配合可编程加密芯片SMEC88ST的防抄板加密方案设计
1063 浏览 0 评论
2395 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
2190 浏览 3 评论
4824 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2333 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-31 04:22 , Processed in 0.526057 second(s), Total 77, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号