M3串口发送不成功可能是什么原因
片子用的STM32F103C8T6,之前正常,后来板子上的串口位置换了,就把串口换了一下,三个串口都用串口1和串口3都发送不出去
USART_SendData(USART1, (u8) ch);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
跑到这里,就一直检测标志位了
串口2能够发送成功,配置一样,试了两块板子,效果一样
可能是哪里的问题呢?
有没有重映射端口?最好把使用的是哪个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 Receiveinterrupts
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
// DisEnable USART1 SendEmptinterrupts
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
// DisEnable USART1 SendCompleteinterrupts
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 Receiveinterrupts
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
// DisEnable USART1 SendEmptinterrupts
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
// DisEnable USART1 SendCompleteinterrupts
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);
}
原来用着好好的啊 就是换了一下顺序
串口如果想要发送数据的话 除了允许发送,打开串口 还需要别的不 zfz0122 发表于 2015-3-20 09:04
板子上的串口位置换了,就把串口换了一下,??没懂
原来用串口1实现功能1,串口2实现功能2,串口3实现功能3
换板子以后,用串口1实现功能3,串口3实现功能1,每个串口的引脚也有变化 不懂帮顶 正在学习串口 感觉好凄惨 都没人理我 楼主串口1用的还是PA9 PA10吗? 安 发表于 2015-3-20 11:17
楼主串口1用的还是PA9 PA10吗?
嗯 是的 引脚可以确认是对的
页:
[1]
2