AnsweredAssumed Answered

USART problem

Question asked by gilmore.alastair on Nov 16, 2010
Latest reply on Nov 17, 2010 by gilmore.alastair
Hi, I've managed to get the example program working which transfers a buffer of text from usart2 to usart3. When I try and output on usart2 to a PC however it seems as if the baud rate is wrong. I just get garbage.

The GPIO config is
 /* Configure USARTy Rx as input floating */
  GPIO_InitStructure.GPIO_Pin = USARTy_RxPin;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
   /* Configure USARTy Tx as push-pull */
  GPIO_InitStructure.GPIO_Pin = USARTy_TxPin;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);

 The RCC config is

The defines are
 #define USARTy                   USART2
  #define USARTy_GPIO              GPIOA
  #define USARTy_CLK               RCC_APB1Periph_USART2
  #define USARTy_GPIO_CLK          RCC_APB2Periph_GPIOA
  #define USARTy_RxPin             GPIO_Pin_3
  #define USARTy_TxPin             GPIO_Pin_2

and the code is
  USART_InitStructure.USART_BaudRate = 9600;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_Even;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  /* Configure USARTy */
  USART_Init(USARTy, &USART_InitStructure);
  /* Enable the USARTy */

  while(TxCounter < TxBufferSize)
    /* Send one byte from USARTy  */
    USART_SendData(USARTy, TxBuffer[TxCounter++]);

    /* Loop until USARTy DR register is empty */
    while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET)

Any help would be appreciated