Skip to main content
opiol
Associate
February 13, 2012
Question

USART Rx problem

  • February 13, 2012
  • 13 replies
  • 2039 views
Posted on February 13, 2012 at 20:16

Hello,

I have a little problem with Rx on stm32f417.

I designed my own board, byt i am putting this here, becouse i cannot find another approperiate forum.

I tried to set up UART2, but i cannot make reciving working.

HW is OK, i tested that.

void USART_Inicializace(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitTypeDef GPIO_InitStructure2;

USART_InitTypeDef USART_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);  // 1.

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE); // 2.

GPIO_PinAFConfig  ( GPIOD, GPIO_PinSource5 , GPIO_AF_USART2) ;

GPIO_PinAFConfig  ( GPIOD, GPIO_PinSource6 , GPIO_AF_USART2) ;  

//  

//   //  Tx

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // alternate function!

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP ;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOD, &GPIO_InitStructure);

////

//   // Rx

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

  GPIO_Init(GPIOD, &GPIO_InitStructure);

//

  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_No;

  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_Init(USART2, &USART_InitStructure);

//

USART_Cmd(USART2, ENABLE);

// jeste zbyva konfigurace preruseni

// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

//

//   NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;

//   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

//   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

//   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

//   NVIC_Init(&NVIC_InitStructure);

// USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);

}

Thank you.
    This topic has been closed for replies.

    13 replies

    Tesla DeLorean
    Guru
    April 24, 2013
    Posted on April 24, 2013 at 13:30

    Check the project's meta data for defines sent to the compilers command line, HSE_VALUE being a primary culprit for mismatched baud rates. Check also the PLL settings correlate with the crystal on your board.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    jean_prieur
    Associate III
    April 24, 2013
    Posted on April 24, 2013 at 13:46

    I just check with a scope, my STM32 is working at 8MHz !! (Instead of 144Mhz)

    Do you know how can check the project's meta data ? I'm not familiar with this...

    Tesla DeLorean
    Guru
    April 24, 2013
    Posted on April 24, 2013 at 15:10

    It's all the stuff under the ''Options'' for a project, probably the C/C++ tabs or whatever the equivalent is in IAR vs CooCox.

    Where the project files are ASCII text (ie XML, etc) you can also comb through them, or makefiles if the tools can generate those.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..