串口1改串口3,直连可行,否则无输出?

2019-07-25 11:43发布

各位大大帮忙看下,我是新手,我在原子哥的程序串口通讯简单实例上改了一点,把串口1改成成了串口3,对应的计时器、中断等也进行了调整,但程序执行后,串口助手输入无输出,我将pb10、pb11与tx、rx直接连接起来,可以输出了。我找了两天没找到问题是什么,想问一下如何将之改为串口3,串口3与串口1与电脑连接需要多设置什么吗?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
9条回答
18983041577
2019-07-25 23:01
本帖最后由 18983041577 于 2017-11-13 17:20 编辑

程序源码为void My_USART3_Init(void) {         GPIO_InitTypeDef GPIO_InitStrue;        
USART_InitTypeDef USART_InitStrue;        
NVIC_InitTypeDef NVIC_InitStrue;                  
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//①        
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);                  
GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF_PP;         
GPIO_InitStrue.GPIO_Pin=GPIO_Pin_10;        
GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;   
GPIO_Init(GPIOB,&GPIO_InitStrue);//②                  
GPIO_InitStrue.GPIO_Mode=GPIO_Mode_IN_FLOATING;        
GPIO_InitStrue.GPIO_Pin=GPIO_Pin_11;         
GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;   
GPIO_Init(GPIOB,&GPIO_InitStrue);//②                 
USART_InitStrue.USART_BaudRate=115200;        
USART_InitStrue.USART_HardwareFlowControl=USART_HardwareFlowControl_None;         
USART_InitStrue.USART_Mode=USART_Mode_Tx|USART_Mode_Rx;        
USART_InitStrue.USART_Parity=USART_Parity_No;         
USART_InitStrue.USART_StopBits=USART_StopBits_1;         
USART_InitStrue.USART_WordLength=USART_WordLength_8b;                  
USART_Init(USART3,&USART_InitStrue);//③                 
USART_Cmd(USART3,ENABLE);//使能串口1                 
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);//开启接收中断                  
NVIC_InitStrue.NVIC_IRQChannel=USART3_IRQn;         
NVIC_InitStrue.NVIC_IRQChannelCmd=ENABLE;        
NVIC_InitStrue.NVIC_IRQChannelPreemptionPriority=1;         
NVIC_InitStrue.NVIC_IRQChannelSubPriority=1;         
NVIC_Init(&NVIC_InitStrue);                  
}
void USART3_IRQHandler(void)
{         
u8 res;         
if(USART_GetITStatus(USART3,USART_IT_RXNE))
{      
res= USART_ReceiveData(USART3);      
USART_SendData(USART3,res);   
}
}   
int main(void)
{         
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);        
My_USART3_Init();         
while(1);            
}

一周热门 更多>