完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
片子用的STM32F103C8T6,之前正常,后来板子上的串口位置换了,就把串口换了一下,三个串口都用
串口1和串口3都发送不出去 USART_SendData(USART1, (u8) ch); while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET); 跑到这里,就一直检测标志位了 串口2能够发送成功,配置一样,试了两块板子,效果一样 可能是哪里的问题呢? |
|
相关推荐
16个回答
|
|
有没有重映射端口?最好把使用的是哪个IO口做串口、配置发一下。
|
|
|
|
板子上的串口位置换了,就把串口换了一下,??没懂
|
|
|
|
void UART1_Configuration(void)
{ GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; Uart1Conf.RXpoint = 0; Uart1Conf.RXStart = Uart1Conf.RXpoint; Uart1Conf.RXlenth = 0; Uart1Conf.TXlenth = 0; Uart1Conf.Time = 0; RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // USART1ʱÖÓʹÄÜ USART_InitStructure.USART_BaudRate = 38400; 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(USART1, &USART_InitStructure); RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ //Configure the USART1_Tx PA9 as Alternate function Push-Pull GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); //Configure the USART1_Rx PA10 as input power-UP GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIOA, &GPIO_InitStructure); RCC_APB2PeriphClockCmd( RS485OUTEN_GPIO_CLK | RS485INEN_GPIO_CLK,ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ // Configure the RS485DoutEN PA11 as out Push-Pull GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = RS485OUTEN_PIN; GPIO_Init(RS485OUTEN_GPIO_PORT, &GPIO_InitStructure); // Configure the RS485RecvEN PA12 as out Push-Pull GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = RS485INEN_PIN; GPIO_Init(RS485INEN_GPIO_PORT, &GPIO_InitStructure); RS485DoutDIS(); // ½ûÖ¹·¢ËÍ RS485RecvEN(); // ½ÓÊÕʹÄÜ // Enable USART1 Receive interrupts USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // DisEnable USART1 SendEmpt interrupts USART_ITConfig(USART1, USART_IT_TXE, DISABLE); // DisEnable USART1 SendComplete interrupts USART_ITConfig(USART1, USART_IT_TC, DISABLE); // USART_ClearFlag(USART1,USART_FLAG_TC); // ·ÀÖ¹ÎÞ·¨Êä³ö¸´Î»ºóµÄÊ××Ö·û£¬Õâ¸ö¹¦ÄÜû·¨ÑéÖ¤ // Enable the USART1 USART_Cmd(USART1, ENABLE); // USART1ʹÄÜ // Enable the USART1 Interrupt NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // USART1ʱÖÓʹÄÜ USART_InitStructure.USART_BaudRate = 38400; 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(USART1, &USART_InitStructure); RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ //Configure the USART1_Tx PA9 as Alternate function Push-Pull GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); //Configure the USART1_Rx PA10 as input power-UP GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIOA, &GPIO_InitStructure); RCC_APB2PeriphClockCmd( RS485OUTEN_GPIO_CLK | RS485INEN_GPIO_CLK,ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ // Configure the RS485DoutEN PA11 as out Push-Pull GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = RS485OUTEN_PIN; GPIO_Init(RS485OUTEN_GPIO_PORT, &GPIO_InitStructure); // Configure the RS485RecvEN PA12 as out Push-Pull GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = RS485INEN_PIN; GPIO_Init(RS485INEN_GPIO_PORT, &GPIO_InitStructure); RS485DoutDIS(); // ½ûÖ¹·¢ËÍ RS485RecvEN(); // ½ÓÊÕʹÄÜ // Enable USART1 Receive interrupts USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // DisEnable USART1 SendEmpt interrupts USART_ITConfig(USART1, USART_IT_TXE, DISABLE); // DisEnable USART1 SendComplete interrupts USART_ITConfig(USART1, USART_IT_TC, DISABLE); // USART_ClearFlag(USART1,USART_FLAG_TC); // ·ÀÖ¹ÎÞ·¨Êä³ö¸´Î»ºóµÄÊ××Ö·û£¬Õâ¸ö¹¦ÄÜû·¨ÑéÖ¤ // Enable the USART1 USART_Cmd(USART1, ENABLE); // USART1ʹÄÜ // Enable the USART1 Interrupt NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } 原来用着好好的啊 就是换了一下顺序 串口如果想要发送数据的话 除了允许发送,打开串口 还需要别的不 |
|
|
|
原来用串口1实现功能1,串口2实现功能2,串口3实现功能3 换板子以后,用串口1实现功能3,串口3实现功能1,每个串口的引脚也有变化 |
|
|
|
不懂帮顶
|
|
|
|
正在学习串口
|
|
|
|
感觉好凄惨 都没人理我
|
|
|
|
楼主串口1用的还是PA9 PA10吗?
|
|
|
|
|
|
|
|
|
|
|
|
一个一个串口试下正常吗
|
|
|
|
恩恩 太马虎了 谢谢 |
|
|
|
楼主可以正常使用了吗?
|
|
|
|
|
|
|
|
|
|
不客气,有问题在论坛发帖就可以了。
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
2049 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1893 浏览 3 评论
4485 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2040 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
2549 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 16:59 , Processed in 0.828883 second(s), Total 69, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号