Skip to main content
lipin
Associate III
May 25, 2010
Question

USART2 Problems

  • May 25, 2010
  • 5 replies
  • 833 views
Posted on May 25, 2010 at 22:49

USART2 Problems

    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    May 17, 2011
    Posted on May 17, 2011 at 13:52

    Is the external clock stable? Check with scope

    Send a repetitive data pattern, check mark/space and character framing on a scope.

    Try the internal high speed clock (1%)

    Show the Tx/Rx code, ideally a small self standing project that can be compiled.

    If the Tx code is not waiting correctly it could be fouling up the USART.

    Try using 2 Stop bits on the STM32 side.

    Try using a different terminal application like RealTerm.

    Try using a different serial port (internal, USB dongle, etc), or different computer.

    I am using all three USARTs on my STM32F103RET6 part. #1 115200 8N1, #2 9600 8N1, #3 115200 8N1 Hardware Flow. The only problem I have is with latency introduced with writing to internal flash.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    May 17, 2011
    Posted on May 17, 2011 at 13:52

    Aren't you missing the SystemInit function in RCC_Configuration()?

    Depends on the library version I suspect, but the code is workable without reprogramming the clocks, the STM32 starts on the internal 8 MHz (HSI) and runs just fine. I modified it to run on USART1 as the MINI32 board I'm using for scratch development only has one serial port exposed, not getting any corruption. I'll have to try it on an STM3210C with two USARTs.

    Also, you should really be using TXE flag to check a character has been sent.

    Indeed, but TC will work, the characters with be output a little more sparsely than using TXE when the characters will be end-on-end.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    John F.
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:52

    Aren't you missing the SystemInit function in RCC_Configuration()?

      //Setup the microcontroller system. Initialize the Embedded Flash Interface, 

      //initialize the PLL and update the SystemFrequency variable.

      SystemInit();

    Also, you should really be using TXE flag to check a character has been sent.

        //send one byte

        USART_SendData(USART3, Character_1);

        //Loop until USART DR register is empty

        while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);

    The TC flag is used to guarantee that the last stop bit of the last character (of several) has been sent (before you power down the USART etc.) See the TC / TXE diagram in RM008 Rev 10. ''Figure 250. TC/TXE behavior when transmitting''.

    Good luck. John F.

    lipin
    lipinAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:52

    Ahh I wish to have oscilloscope. You may be right about hardware problem like USB dongle. Anyway here is simple HSI project if someone with a lot of time can check if it is working. I is going to be big help for me. Thank you.

    #include ''stm32f10x.h''

    #include ''usart.h''

    // USART Pins

    #define USART_TX  GPIO_Pin_2

    #define USART_RX  GPIO_Pin_3

    void RCC_Conf() {

      // Set USART and GPIOA clock

      RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

    }

    void GPIO_Conf() {

      GPIO_InitTypeDef GPIO_InitStructure;

        // Tx Line Config

      GPIO_InitStructure.GPIO_Pin = USART_TX;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

      GPIO_Init(GPIOA, &GPIO_InitStructure);

      // Rx Line Config

      GPIO_InitStructure.GPIO_Pin = USART_RX;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

      GPIO_Init(GPIOA, &GPIO_InitStructure);

    }

    int main()

    {

      USART_InitTypeDef USART_InitStructure;

      

      RCC_Conf();

      GPIO_Conf();

      // USART Settings

      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 & Enable

      USART_Init(USART2, &USART_InitStructure);

      USART_Cmd(USART2, ENABLE);

      while (!0) {

        // Send 1 character

        USART_SendData(USART2, '&');

        // Wait for send

        while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET) {}

      }

    }

    Regards

    Thomas

    lipin
    lipinAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:52

    Thank you. I took you advice of using TXE flag code is valid problem was in usb rs232 converter.

    Regards

    Thomas