AnsweredAssumed Answered

stm32 USART synchronous Mode

Question asked by Adeli on Feb 20, 2013
Latest reply on Feb 20, 2013 by Clive One
hello
I want to use synchronous mode Usart
But I'm totally confused
When I activate the clock
I can not determine if Master or Slave?
Please help Me


  USART_InitTypeDef USART_InitStruct;
        GPIO_InitTypeDef GPIO_InitStructure;
    USART_ClockInitTypeDef  USART_ClockInitStructure;
 
//-----------------------------------------------------------------------
        RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA ,ENABLE);
        RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2 , ENABLE );
//---------Configure USART1 Tx (PA.09) as alternate function push-pull
       // GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
         
      GPIO_InitStructure.GPIO_Pin =   GPIO_PIN_KeyBoard_TXD ;
      GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_AF_PP;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_Init(GPIO_KeyBoard, &GPIO_InitStructure);
//------------------------------------------------------------------------
          GPIO_InitStructure.GPIO_Pin =   GPIO_PIN_KeyBoard_SCK ;
      GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_Out_OD;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_Init(GPIO_KeyBoard, &GPIO_InitStructure);
//------------------------------------------------------------------------       
          GPIO_InitStructure.GPIO_Pin =   GPIO_PIN_KeyBoard_RXD;
          GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_IN_FLOATING;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_Init(GPIO_KeyBoard, &GPIO_InitStructure);
//  ----------------------------------------------------------------------     
  /* USART_InitStruct members default value */
  USART_InitStruct.USART_BaudRate = 9600;
  USART_InitStruct.USART_WordLength = USART_WordLength_8b;
  USART_InitStruct.USART_StopBits = USART_StopBits_1;
  USART_InitStruct.USART_Parity =USART_Parity_No ;//USART_Parity_No;// USART_Parity_Odd ;
  USART_InitStruct.USART_Mode =  USART_Mode_Tx ;
  USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
   
   
  USART_ClockStructInit(&USART_ClockInitStructure);
  //------------------------------------------------------------------------- 
  USART_ClockInitStructure.USART_Clock = USART_Clock_Enable;
  USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
  USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
  USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
//-------------------------------------------------------------------------
  USART_ClockInit(USART2, &USART_ClockInitStructure);
   
   
  USART_Init(USART2, &USART_InitStruct);/* Configure the USART2 */
  USART_Cmd(USART2,ENABLE);                      /* Enable the USART2 */
  USART_ITConfig(USART2, USART_IT_RXNE , ENABLE);/* Enable USART2 interrupt */
  NVIC_Configuration_Usart2();

Outcomes