Skip to main content
jgalea
Associate III
February 11, 2009
Question

USART setup example

  • February 11, 2009
  • 12 replies
  • 1815 views
Posted on February 11, 2009 at 13:27

USART setup example

    This topic has been closed for replies.

    12 replies

    st3
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:02

    The ST FWLib includes a whole section full of USART examples.

    Your tool provider probably also provides examples - like the classic ''Hello, World!''

    jgalea
    jgaleaAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:02

    Hello everyone. Please can anyone indicate to me a good example about USART setup in STM32F101x4? Many Thanks Johann

    kaouther
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:02

    Here is the link for the

    http://www.st.com/mcu/modules.php?name=mcu&file=familiesdocs&FAM=110#Firmware

    .

    Enjoy it ;)

    jgalea
    jgaleaAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:02

    Thanks. Please is it possible to indicate where the library is on the ST site as could not find it. many thanks Johann

    jgalea
    jgaleaAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:02

    Thanks. If a set up the code will put it on the forum as I did with the DMA Johann

    jgalea
    jgaleaAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:02

    Hello found the link but could not find the example Hello World. Im following other examples but still cannot transmit to the hyperterminal. Im using and IC to convert to the required logic signals. Thanks Johann

    jgalea
    jgaleaAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:02

    Dear brunoalltest. Many thanks the USART is transmitting. However I'm getting a different character in the hyperterminal. Please if you have time,do I need to use this line:

    USART_SendData(USART1, 0x26); //38 decimal

    /* Loop until the end of transmission */

    while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)

    {}

    Im putting this line in a timer interrupt every 200us/

    Thanks

    Johann

    brunoalltest
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:02

    You need to activate the clock of the serial before using any usart function.

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE)

    You also need to configure the usart pins with something like this

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

    /* USART1 Rx */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

    GPIO_Init(GPIOA, &GPIO_InitStructure);

    /* USART1 Tx */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

    GPIO_Init(GPIOA, &GPIO_InitStructure);

    jgalea
    jgaleaAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:02

    im using this code: Thanks

    void USART_Set_up(void)

    {

    USART_InitTypeDef USART_InitStructure; //declaration of structure

    // USART_ClockInitTypeDef USART_ClockInitStructure;

    USART_DeInit(USART1); //places USART1 to default reset value

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

    USART_Init(USART1, &USART_InitStructure);

    /* Enable the USART Transmoit interrupt: this interrupt is generated when the

    USART1 transmit data register is empty */

    //USART_ITConfig(USART1, USART_IT_TXE, ENABLE);

    /* Enable the USARTx */

    USART_Cmd(USART1, ENABLE);

    }

    /* Send one HalfWord on USART1 */

    USART_SendData(USART1, 0x26); //38 decimal

    brunoalltest
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:02

    You´re sending 0x26 ( '&' in the ascii table)

    If you´re not receiving a '&' in hyperterminal maybe your baudrate configuration is wrong(you need to set 9600 on hyperterminal).

    Or maybe your ''#define HSE_Value'' on ''stm32f10x_conf.h'' is wrong.