Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8981639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:23:11+00:00 2026-06-15T20:23:11+00:00

I am having issues trying to use the UART (USART1) on my F4Discovery board

  • 0

I am having issues trying to use the UART (USART1) on my F4Discovery board (based on an STM32F407). I am pretty new to STM32 and Keil (the IDE I am using). Here’s my code:

#include "stm32f4_discovery.h"
#include "stm32f4xx_usart.h"
#include "stm32f4xx.h"

void usartSetup(void);
void USART_PutChar(uint8_t ch);

int main (void) {
    usartSetup();

    USART_PutChar(0);   //I realise this won't send a 0
    USART_PutChar(8);   //I realise this won't send an 8
    USART_PutChar(255);   //I realise this won't send a 255

    while (1) {
        //loop forever
    }
}

void usartSetup (void) {
    USART_InitTypeDef USART_InitStructure;
    //USART_StructInit(&USART_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(USART1, &USART_InitStructure);
    USART_Cmd(USART1, ENABLE);
}

void USART_PutChar(uint8_t ch) {
    USART_SendData(USART1, (uint16_t) 0x49);
    while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
    USART_SendData(USART1, (uint16_t) 0x49);
}

I’d be very grateful if someone could help. It never sends the 0x49 out of the UART1 TX (have checked pin PA9 and PB6) and then gets endlessly stuck on the while(USART_GetFlagStatus…). I am observing using the Keil debugger and see it get stuck in the while.

I am including the stm32f4xx_usart.c driver into the project.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:23:13+00:00Added an answer on June 15, 2026 at 8:23 pm

    You haven’t configured output pins to use USART and clocks. If you use USART1 or USART6, you will have to set APB2 clock (highspeed) against APB1 (lowspeed)

    /* For output on GPIOA */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2);
    
    /* Output pins configuration, change M and N index! */
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_N | GPIO_Pin_M;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // Push - pull
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    
    GPIO_PinAFConfig(GPIOA, GPIO_PinSourceN, GPIO_AF_USART2);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSourceM, GPIO_AF_USART2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Being new to android, I’m having some issues. Currently I’m trying to make use
I am having serious issues trying to use the Javascript API for facebook. I
I'm trying to use the paperclip-dropbox gem here , and I'm having issues with
Im trying to use the call back after_find in my model, I'm having issues
I am new to lambda expressions and I am having issues trying to figure
I'm having some issues trying to use the LEFT() function with a multi-valued parameter
I am trying to use a C++ DLL in C# and having some issues
I am trying to use a Dynamic Data Application and having issues with customizing
I am currently trying to use the Thrust library and I am having issues
I'm having some issues because I'm trying to re-use code (which can be used)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.