完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
最近在调试STM32串口,发现串口发送数据总是进入如下死循环 while(USART_GetFlagStatus(UART5, USART_FLAG_TXE) == RESET); 经检查发现串口时钟没有开,打开串口时钟后串口发送数据正常 RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); //打开串口时钟 附上串口配置完整代码 void uart_init(void) { /* 定义结构体变量 */ GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /*开启时钟 */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE); //ʹÄÜUSART1£¬GPIOAʱÖÓ RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); //ʹÄÜUSART1£¬GPIOAʱÖÓ /* 初始化GPIO口*/ //RS4851 USART1_TX GPIOA.9 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸´ÓÃÍÆÍìÊä³ö GPIO_Init(GPIOA, &GPIO_InitStructure);//³õʼ»¯GPIOA.9 //USART1_RX GPIOA.10³õʼ»¯ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//PA10 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//¸¡¿ÕÊäÈë GPIO_Init(GPIOA, &GPIO_InitStructure);//³õʼ»¯GPIOA.10 //RS4851 RE/DE GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//PB0 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;// ÍÆÍìÊä³ö GPIO_Init(GPIOB, &GPIO_InitStructure); //UART5_TX GPIOC.12 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //PC12 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸´ÓÃÍÆÍìÊä³ö GPIO_Init(GPIOC, &GPIO_InitStructure);//³õʼ»¯PC12 //UART5_RX GPIOD.2³õʼ»¯ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;//PD2 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//¸¡¿ÕÊäÈë GPIO_Init(GPIOD, &GPIO_InitStructure);//³õʼ»¯GPIOD.2 /* NVICÅäÖà */ //Usart1 NVIC ÅäÖà NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3 ; //ÇÀÕ¼ÓÅÏȼ¶3 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //×ÓÓÅÏȼ¶3 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨµÀʹÄÜ NVIC_Init(&NVIC_InitStructure); //¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯VIC¼Ä´æÆ÷ //Uart5 NVIC ÅäÖà NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3 ; //ÇÀÕ¼ÓÅÏȼ¶3 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //×ÓÓÅÏȼ¶2 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨµÀʹÄÜ NVIC_Init(&NVIC_InitStructure); //¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯VIC¼Ä´æÆ÷ /* USARTÅäÖà */ //USART1 ³õʼ»¯ÉèÖà USART_InitStructure.USART_BaudRate = 9600;//´®¿Ú²¨ÌØÂÊ USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö³¤Îª8λÊý¾Ý¸ñʽ 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(USART1, &USART_InitStructure); //³õʼ»¯´®¿Ú1 //UART5 ³õʼ»¯ÉèÖà USART_InitStructure.USART_BaudRate = 9600;//´®¿Ú²¨ÌØÂÊ USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö³¤Îª8λÊý¾Ý¸ñʽ 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(UART5, &USART_InitStructure); //³õʼ»¯´®¿Ú5 USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //¿ªÆô´®¿Ú1½ÓÊÜÖÐ¶Ï USART_ITConfig(UART5, USART_IT_RXNE, ENABLE); //¿ªÆô´®¿Ú5½ÓÊÜÖÐ¶Ï USART_Cmd(USART1, ENABLE); //ʹÄÜ´®¿Ú1 USART_Cmd(UART5, ENABLE); //ʹÄÜ´®¿Ú5 } 以上为完成配置代码。 |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1804 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1629 浏览 1 评论
1097 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
736 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1686 浏览 2 评论
1944浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
748浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
583浏览 3评论
604浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
565浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-29 00:46 , Processed in 0.640523 second(s), Total 47, Slave 41 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号