新人关于第26讲实验程序

2019-07-20 05:21发布

本人探索者F4开发板,跟着第26讲实验程序写了串口通信程序,实现的功能就是利用串口调试助手发送信息可以送到电脑上,但是代码烧进去打开串口助手却没反应,不知道哪里错了,找了很久,希望大神帮下。主程序代码如下
#include "sys.h"
#include "delay.h"
#include"led.h"
#include"usart.h"



void myusartinit()
{
        GPIO_InitTypeDef GPIO_Initinstruct;
        USART_InitTypeDef USART_Initinstruct;
        NVIC_InitTypeDef NVIC_Initinstruct;
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
        RCC_AHB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
       
        GPIO_Initinstruct.GPIO_Pin=GPIO_Pin_9|GPIO_Pin_10;
        GPIO_Initinstruct.GPIO_Mode=GPIO_Mode_AF;
        GPIO_Initinstruct.GPIO_OType=GPIO_OType_PP;
        GPIO_Initinstruct.GPIO_PuPd=GPIO_PuPd_UP;
        GPIO_Initinstruct.GPIO_Speed=GPIO_Speed_100MHz;
        GPIO_Init(GPIOA,&GPIO_Initinstruct);//端口模式设置
       
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1);//引脚复用映射
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);
       
        USART_Initinstruct.USART_BaudRate=115200;//串口初始化
        USART_Initinstruct.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
        USART_Initinstruct.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
        USART_Initinstruct.USART_Parity=USART_Parity_No;
        USART_Initinstruct.USART_StopBits=USART_StopBits_1;
        USART_Initinstruct.USART_WordLength=USART_WordLength_8b;
        USART_Init(USART1,&USART_Initinstruct);
        //使能串口
        USART_Cmd(USART1,ENABLE);
        USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//使能接收非空会中断
        NVIC_Initinstruct.NVIC_IRQChannel=USART1_IRQn;//通道在f4xx.h
        NVIC_Initinstruct.NVIC_IRQChannelCmd=ENABLE;
        NVIC_Initinstruct.NVIC_IRQChannelPreemptionPriority=1;
        NVIC_Initinstruct.NVIC_IRQChannelSubPriority=1;
        NVIC_Init(&NVIC_Initinstruct);
       
       
}
void USART1_IRQHandler()
{
        u8 res;
        if(USART_GetITStatus(USART1,USART_IT_RXNE))
        {
        res=USART_ReceiveData(USART1);
        USART_SendData(USART1,res);
        }
}


int main(void)
{
       
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
        myusartinit();
        while(1);
       
}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。