stm32 DMX512核心代碼

while (1)
{
   USART_Cmd(USART2, DISABLE);
   GPIO_Tx_Normal_Config();
   GPIO_ResetBits(GPIOD,GPIO_Pin_5);//低orm

   Delay(100us); //延時至少88us
   GPIO_SetBits(GPIOD,GPIO_Pin_5); //拉高it

    USART_initial(); //耗時間
   USART_SendData(USART2,0x00);
   while(USART_GetFlagStatus(USART2,USART_FLAG_TC) == RESET)
   {}
   for(i = 0; i< 512; i++)
   {
    USART2->DR = DMX[i];
    while(USART_GetFlagStatus(USART2,USART_FLAG_TC) == RESET)
    {}
  }   
}配置

發送 接收配置top

  USART_InitTypeDef USART_InitStructure;
  USART_InitStructure.USART_BaudRate = 250000;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b; //接收時9  發送爲8
  USART_InitStructure.USART_StopBits = USART_StopBits_2;  //接收時爲1  發送爲2
  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(USART2, &USART_InitStructure);
  USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); /* Enable USART2 Receive interrupts */
  USART_Cmd(USART2, ENABLE);時間

相關文章
相關標籤/搜索