F4串口问题

2019-07-20 13:06发布

代码如下 用助手接收不到数据,请问啥原因
void usart_init()
{
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
        RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1 ,ENABLE);
        RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA ,ENABLE);
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_Pin =GPIO_Pin_9|GPIO_Pin_10;
        GPIO_InitStructure.GPIO_OType =GPIO_OType_PP;//íÆíìêä3ö
        GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_UP;//éÏà-
        GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
        GPIO_Init(GPIOA,&GPIO_InitStructure);
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1);
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);
        USART_InitStructure .USART_BaudRate =9600;
        USART_InitStructure.USART_HardwareFlowControl =USART_HardwareFlowControl_None ;//ûóDó2¼t¿ØÖÆá÷
        USART_InitStructure .USART_Mode =USART_Mode_Rx |USART_Mode_Tx;
        USART_InitStructure .USART_Parity =USART_Parity_No ;//ûóDÆæżD£Ñéλ
        USART_InitStructure.USART_StopBits =USART_StopBits_1;
        USART_InitStructure.USART_WordLength =USART_WordLength_8b ;//êy¾Y3¤¶è8λ
        USART_Init (USART1,&USART_InitStructure);
        USART_Cmd(USART1,ENABLE);//′®¿úê1Äü
}
int main ()
{
        char i;
        usart_init();
        led_init();
       
        for(i=0;i<9;i++)
                {
                        USART_SendData (USART1,i);
               
                        while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);       
                        GPIO_ResetBits(GPIOF,GPIO_Pin_9);
                }
       
}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
shadow1
1楼-- · 2019-07-20 15:47
shadow1 发表于 2017-7-26 09:59
我试了你的程序做了一些改动,可以正常接收

void usart1_init()
{
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
        RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1 ,ENABLE);
        RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA ,ENABLE);
       

        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_Pin =GPIO_Pin_9|GPIO_Pin_10;
        GPIO_InitStructure.GPIO_OType =GPIO_OType_PP;//í&#198;íìê&#228;3&#246;
        GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_UP;//é&#207;à-
        GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
        GPIO_Init(GPIOA,&GPIO_InitStructure);
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1);
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);
        USART_InitStructure .USART_BaudRate =9600;
        USART_InitStructure.USART_HardwareFlowControl =USART_HardwareFlowControl_None ;//&#195;&#187;óDó2&#188;t&#191;&#216;&#214;&#198;á÷
        USART_InitStructure .USART_Mode =USART_Mode_Rx |USART_Mode_Tx;
        USART_InitStructure .USART_Parity =USART_Parity_No ;//&#195;&#187;óD&#198;&#230;&#197;&#188;D?&#209;é&#206;&#187;
        USART_InitStructure.USART_StopBits =USART_StopBits_1;
        USART_InitStructure.USART_WordLength =USART_WordLength_8b ;//êy&#190;Y3¤&#182;è8&#206;&#187;
        USART_Init (USART1,&USART_InitStructure);
        USART_Cmd(USART1,ENABLE);//'&#174;&#191;úê1&#196;ü
}
int main ()
{
              unsigned char a[26]={65,66,67};
        unsigned char i;
                                delay_init(168);
        usart1_init();
       // led_init();
        LED_Init();  
                                while(1)
                                {
        for(i=0;i<3;i++)
                {
                        USART_SendData (USART1,a);
               
                        while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);        
                       // GPIO_ResetBits(GPIOF,GPIO_Pin_9);
                                                                               LED0=!LED0;   
                }
                                        delay_ms(1000);                       
                                        }
}
shadow1
2楼-- · 2019-07-20 21:27
 精彩回答 2  元偷偷看……

一周热门 更多>