Skip to main content
shaktishekhar789
Associate III
February 26, 2013
Question

STM32W108xx UART implementation

  • February 26, 2013
  • 23 replies
  • 3604 views
Posted on February 26, 2013 at 10:10

Hi 

I want to show the output(i.e. sended data) on tera term terminal. How to setup tera term for that.(I am using UART for serial communication in which i am sending data from one port and receiving from other one.) Please reply me asap.

    This topic has been closed for replies.

    23 replies

    shaktishekhar789
    Associate III
    February 28, 2013
    Posted on February 28, 2013 at 06:13

    Thanks for your reply.Should I implement UART on STM32F10XX eval board.? It has connected UART on board. Please give me your suggestion. 

    shaktishekhar789
    Associate III
    February 28, 2013
    Posted on February 28, 2013 at 10:11

    I have written and run this following code on IAR for STM32F10X. It compiled but i am not able to see that the data i am sending is written to data register of uart or not. I even debug and download the code on stm32f10xx eval board , set breakpoint etc.

    /* Code for sending data through UART(evaluation board STM32F10x)

    #include<stdio.h>

    #include ''stm32f10x.h''

    #include ''stm32f10x_rcc.h''

    #include ''stm32f10x_gpio.h''

    #include ''stm32f10x_usart.h''

    void outstring(char *s)

    {

      while(*s)

      {

        /* Loop until transmit data register is empty */

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

     

        USART_SendData(UART4, (uint8_t)*s++);

        printf(''%u'',UART4->DR);

      }

    }

     

    int main(void)

    {

      USART_InitTypeDef USART_InitStructure;

      GPIO_InitTypeDef GPIO_InitStructure;

     

      /* Disable the serial controller interface */

      USART_Cmd(UART4, DISABLE);

     

      /* Configure (PC10) UART4 Tx as alternate function push-pull */

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

      GPIO_Init(GPIOC, &GPIO_InitStructure);

      /* Set pull-up on UART Tx pin */

      GPIO_SetBits(GPIOC, GPIO_Pin_10);

     

      /* Configure (PC11) UART4 Rx as input with pull-up */

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

      GPIO_Init(GPIOC, &GPIO_InitStructure);

      /* Set pull-up on UART Rx pin */

      GPIO_SetBits(GPIOC, GPIO_Pin_11);

     

      /* UARTx configured as follow:

            - BaudRate =  9600 baud

            - Word Length = 8 Bits

            - One Stop Bit

            - No parity

            - Hardware flow control disabled (RTS and CTS signals)

      */

      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;

     

      /* UART configuration: Set up the parameters specific for the UART operating mode */

      USART_Init(UART4, &USART_InitStructure);

     

      /* Enable the UART peripheral */

      USART_Cmd(UART4, ENABLE);

     

      while(1)

        outstring(''Welcome to wherever you are!\r\n'');

    }

    Tesla DeLorean
    Guru
    February 28, 2013
    Posted on February 28, 2013 at 12:59

    Needs some clock initialization on the F1

    #include <
    stdio.h
    >
    #include ''stm32f10x.h''
    #include ''stm32f10x_rcc.h''
    #include ''stm32f10x_gpio.h''
    #include ''stm32f10x_usart.h''
    void outstring(char *s)
    {
    while(*s)
    {
    /* Loop until transmit data register is empty */
    while (USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET);
    USART_SendData(UART4, (uint8_t)*s++);
    }
    }
    int main(void)
    {
    USART_InitTypeDef USART_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); /* Enable GPIOC */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); /* Enable UART4 */
    /* Configure (PC10) UART4 Tx as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    /* Configure (PC11) UART4 Rx as input with pull-up */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    /* UARTx configured as follow:
    - BaudRate = 9600 baud
    - Word Length = 8 Bits
    - One Stop Bit
    - No parity
    - Hardware flow control disabled (RTS and CTS signals)
    */
    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;
    /* UART configuration: Set up the parameters specific for the UART operating mode */
    USART_Init(UART4, &USART_InitStructure);
    /* Enable the UART peripheral */
    USART_Cmd(UART4, ENABLE);
    while(1)
    outstring(''Welcome to wherever you are!
    
    '');
    }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    shaktishekhar789
    Associate III
    February 28, 2013
    Posted on February 28, 2013 at 15:36

    Thanks for reply. I have donr the same thing but I am not able to read the data register contents . I put printf statement as ''printf(''%u'',UART->DR);'' and debug but I am getting 0 on I/o terminal. please tell me how to get the exact sended data.

    Tesla DeLorean
    Guru
    February 28, 2013
    Posted on February 28, 2013 at 15:46

    Reading DR would show receiveded data not sended data

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    shaktishekhar789
    Associate III
    February 28, 2013
    Posted on February 28, 2013 at 16:00

    Then How I able to see the sended data? please reply me

    Tesla DeLorean
    Guru
    February 28, 2013
    Posted on February 28, 2013 at 19:26

    Once you have sent data it enter internal registers you cannot see. The output will be sent to your terminal (Tera Term, Real Term, whatever), if you have it wired and set up correctly.

    Data sent from the terminal will be received by the STM32, you can observe reception by examining the RXNE bit of the status register (SR), and then reading the data register (DR) in response. If the STM32 doesn't receive any data you will need to examine the connectivity.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    shaktishekhar789
    Associate III
    March 1, 2013
    Posted on March 01, 2013 at 03:57

    Thanks for reply. I have TeraTerm. When I connected my eval board by usb it selected in the catagory of disk drives. Please tell me how to make wire connectivity so that i can see the sended data on the terminal.

    Tesla DeLorean
    Guru
    March 1, 2013
    Posted on March 01, 2013 at 13:03

    Awesome, use a serial cable and attach it to the DB9 on your non-specific ST32F1xx board, not USB.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    shaktishekhar789
    Associate III
    March 1, 2013
    Posted on March 01, 2013 at 14:29

    Thanks for your response sir.But In STM32F10x UART is wired connected so is it necessary to connect serial cable to DB9?