STM32F103C8T6的RS485通讯乱码问题

2019-08-19 19:03发布

我和电脑波特率一样,怎么一直接收不到正确的数据,请大家解决一下,谢谢了 这是我的程序
void USART2_485_init(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
  USART_InitTypeDef USART_InitStruct;

       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);   
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);  

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;           //CS_485  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;      //????  
  GPIO_Init(GPIOA, &GPIO_InitStructure);     
                GPIO_ResetBits(GPIOA,GPIO_Pin_1);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;        //??2  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;       //??????  
  GPIO_Init(GPIOA, &GPIO_InitStructure);                //TX???  

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;  
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;        //??3  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //????         
  GPIO_Init(GPIOA, &GPIO_InitStructure);   
       
        USART_InitStruct.USART_BaudRate=15200;
        USART_InitStruct.USART_HardwareFlowControl=USART_HardwareFlowControl_None ;
        USART_InitStruct.USART_Mode=USART_Mode_Rx| USART_Mode_Tx;
        USART_InitStruct.USART_Parity=USART_Parity_No;
        USART_InitStruct.USART_StopBits=USART_StopBits_1;
        USART_InitStruct.USART_WordLength=USART_WordLength_8b;
       
        USART_Init(USART2,&USART_InitStruct);

       
        USART_Cmd(USART2,ENABLE);

       

}


int main()
{


        delay_init();

        USART2_485_init();

                GPIO_SetBits(GPIOA,GPIO_Pin_1);
        while(1)
        {
                USART_SendData(USART2,0x11);
        }

}

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