完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
|
|
相关推荐
1个回答
|
|
RCC时钟
由于设备APB(外部时钟中线)不一样,USART1用的是APB2,USART2~UART5用的是APB1,不注意是容易导致时钟启动失败: typedef struct { USART_TypeDef * UARTx; uint8_t NVIC_IRQChannel; uint32_t comClk; uint32_t TXPortClk; uint32_t RXPortClk; GPIO_TypeDef * TxPort; uint16_t TxPin; GPIO_TypeDef * RxPort; uint16_t RxPin; uint8_t IRQPrio; }boardCOMCfg; boardCOMCfg boardComCfg[comNum] = { { USART1, USART1_IRQn, RCC_APB2Periph_USART1, RCC_APB2Periph_GPIOA, RCC_APB2Periph_GPIOA, GPIOA, GPIO_Pin_9, GPIOA, GPIO_Pin_10 ,3}, { USART2, USART2_IRQn, RCC_APB1Periph_USART2, RCC_APB2Periph_GPIOA, RCC_APB2Periph_GPIOA, GPIOA, GPIO_Pin_2, GPIOA, GPIO_Pin_3 ,3}, { USART3, USART3_IRQn, RCC_APB1Periph_USART3, RCC_APB2Periph_GPIOB, RCC_APB2Periph_GPIOB, GPIOB, GPIO_Pin_10, GPIOB, GPIO_Pin_11 ,3}, { UART4, UART4_IRQn, RCC_APB1Periph_UART4, RCC_APB2Periph_GPIOC, RCC_APB2Periph_GPIOC, GPIOC, GPIO_Pin_10, GPIOC, GPIO_Pin_11 ,2}, { UART5, UART5_IRQn, RCC_APB1Periph_UART5, RCC_APB2Periph_GPIOC, RCC_APB2Periph_GPIOD, GPIOC, GPIO_Pin_12, GPIOD, GPIO_Pin_2 ,1} }; u8 boardComInit(u8 comX,u32 bound){ GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; //comX ·¶Î§ÊÇ1-5 if(comX==0 || comX>5) { return 1; } if(comX == 1) RCC_APB2PeriphClockCmd(boardComCfg[comX-1].comClk , ENABLE); else RCC_APB1PeriphClockCmd(boardComCfg[comX-1].comClk , ENABLE); RCC_APB1PeriphClockCmd(boardComCfg[comX-1].TXPortClk , ENABLE); RCC_APB2PeriphClockCmd(boardComCfg[comX-1].RXPortClk, ENABLE); USART_DeInit(boardComCfg[comX-1].UARTx); /* Configure USART Tx as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = boardComCfg[comX-1].TxPin; //PA.9 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(boardComCfg[comX-1].RxPort, &GPIO_InitStructure); /* Configure USART Rx as input floating */ GPIO_InitStructure.GPIO_Pin = boardComCfg[comX-1].RxPin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(boardComCfg[comX-1].TxPort, &GPIO_InitStructure); //USART USART_InitStructure.USART_BaudRate = bound; 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_Rx | USART_Mode_Tx; USART_Init(boardComCfg[comX-1].UARTx, &USART_InitStructure); //NVIC NVIC_InitStructure.NVIC_IRQChannel = boardComCfg[comX-1].NVIC_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ; NVIC_InitStructure.NVIC_IRQChannelSubPriority = boardComCfg[comX-1].IRQPrio; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_ITConfig(boardComCfg[comX-1].UARTx, USART_IT_RXNE, ENABLE); USART_Cmd(boardComCfg[comX-1].UARTx, ENABLE); return 0; } |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1784 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1621 浏览 1 评论
1088 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
729 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1680 浏览 2 评论
1938浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
734浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
570浏览 3评论
596浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
559浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 20:13 , Processed in 0.724423 second(s), Total 75, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号