AnsweredAssumed Answered

wrong usart baudrate after change of crystal

Question asked by Inok on Jun 30, 2014
Latest reply on Jul 1, 2014 by Inok
Hello all,

I am using STM32F205 and have proper working usarts 1,3+6 with a 8MHz crystal. Now I recevied new hardware with a 16MHz crystal. I created the system_stm32f2xx.c using the tool STM32F2xx_Clock_Configuration_V1.2.0.xls which produces (for the new design)

  *=============================================================================
  *        Supported STM32F2xx device revision    | Rev B and Y
  *-----------------------------------------------------------------------------
  *        System Clock source                    | PLL (HSE)
  *-----------------------------------------------------------------------------
  *        SYSCLK(Hz)                             | 120000000
  *-----------------------------------------------------------------------------
  *        HCLK(Hz)                               | 120000000
  *-----------------------------------------------------------------------------
  *        AHB Prescaler                          | 1
  *-----------------------------------------------------------------------------
  *        APB1 Prescaler                         | 4
  *-----------------------------------------------------------------------------
  *        APB2 Prescaler                         | 2
  *-----------------------------------------------------------------------------
  *        HSE Frequency(Hz)                      | 16000000
  *-----------------------------------------------------------------------------
  *        PLL_M                                  | 16
  *-----------------------------------------------------------------------------
  *        PLL_N                                  | 240
  *-----------------------------------------------------------------------------
  *        PLL_P                                  | 2
  *-----------------------------------------------------------------------------
  *        PLL_Q                                  | 5
  *-----------------------------------------------------------------------------
  *        PLLI2S_N                               | NA
  *-----------------------------------------------------------------------------
  *        PLLI2S_R                               | NA
  *-----------------------------------------------------------------------------
  *        I2S input clock                        | NA
  *-----------------------------------------------------------------------------
  *        VDD(V)                                 | 3.3
  *-----------------------------------------------------------------------------
  *        Flash Latency(WS)                      | 3
  *-----------------------------------------------------------------------------
  *        Prefetch Buffer                        | ON
  *-----------------------------------------------------------------------------
  *        Instruction cache                      | ON
  *-----------------------------------------------------------------------------
  *        Data cache                             | ON
  *-----------------------------------------------------------------------------
  *        Require 48MHz for USB OTG FS,          | Enabled
  *        SDIO and RNG clock                     |
  *-----------------------------------------------------------------------------





This is usart configuration

void USART6_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStruct; /* this is for the GPIO pins used as TX and RX*/
    USART_InitTypeDef USART_InitStruct; /* this is for the USART1 initilization*/
    NVIC_InitTypeDef NVIC_InitStructure; /* this is used to configure the NVIC (nested vector interrupt controller)*/

    /* enable APB2 peripheral clock for USART6
     * note that only USART1 and USART6 are connected to APB2
     * the other USARTs are connected to APB1
     */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);

    /* enable the peripheral clock for the pins used by
     * USART1, PC6 for TX and PC7 for RX
     */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

    /* This sequence sets up the TX and RX pins
     * so they work correctly with the USART6 peripheral
     */
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;     /* Pins 6 (TX) and 7 (RX) are used*/
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;                 /* the pins are configured as alternate function so the USART peripheral has access to them*/
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;            /* this defines the IO speed and has nothing to do with the baudrate!*/
    GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;                /* this defines the output type as push pull mode (as opposed to open drain)*/
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;                /* this activates the pullup resistors on the IO pins*/
    GPIO_Init(GPIOC, &GPIO_InitStruct);                        /* now all the values are passed to the GPIO_Init() function which sets the GPIO registers*/

    /* The RX and TX pins are now connected to their AF
     * so that the USART6 can take over control of the
     * pins
     */
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);

    /* Now the USART_InitStruct is used to define the
     * properties of USART6
     */
   
   
    USART_InitStruct.USART_BaudRate = USART6_BAUDRATE;                /* the baudrate is set to the value we defined before*/
    USART_InitStruct.USART_WordLength = USART_WordLength_8b;  /* we want the data frame size to be 8 bits (standard)*/
    USART_InitStruct.USART_StopBits = USART_StopBits_1;            /* we want 1 stop bit (standard)*/
    USART_InitStruct.USART_Parity = USART_Parity_No;              /* we don't want a parity bit (standard)*/
    USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; /* we don't want flow control (standard)*/
    USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; /* we want to enable the transmitter and the receiver*/
    USART_Init(USART6, &USART_InitStruct);                              /* again all the properties are passed to the USART_Init function which takes care of all the bit setting*/


    /* Here the USART6 receive interrupt is enabled
     * and the interrupt controller is configured
     * to jump to the USART6_IRQHandler() function
     * if the USART1 receive interrupt occurs
     */
    USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);                         /* enable the USART6 receive interrupt*/

As far as I understand, the usart should be driven by the peripherial clock but these clocks should be the same as before because I changed  PLL_M from 8 to 16

Has anybody an idea what is wrong in my configuration or aren't the usart clocks driven by the peripherial clock?
 
Thanks for any help

Outcomes