USART1 issue with a STM32F030R8 Nucleo Board

Guest #3658640
Rate this post
• ▲ useful
▼ not useful
Hello,

As the title says, I have an issue programming my Nucleo's USART1. It 
seems I am missing something. I had to configure solder bridges in order 
to connect USART1 to Pin PA_2(Tx) and PA_3(Rx) by hardware. I checked 
the connexions and PA_2 and PA_3 are connected to the MCU. Here is my 
code :

main.c :
1
#include "main.h"
2

3

4
int main(void)
5
{
6
    Init();
7

8
    while(1)
9
    {   
10
        USART_SendData(USART1, 0xFF);      
11
        while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); 
12
    }
13
}
14

15

16
/*******************************************************************************
17
* Function Name  : Init
18
* Description    : Initializes USART, GPIOS, Clocks
19
* Input          : None
20
* Output         : None
21
* Return         : None
22
*******************************************************************************/
23

24
void Init(void)
25
{
26

27
    
28
    RCC_HSEConfig(RCC_HSE_OFF); // We are using the Internal clock source
29

30
    /* Initialize Reset Clock Control */
31

32
    RCC_ClocksTypeDef RCC_Clocks;
33
    RCC_GetClocksFreq(&RCC_Clocks);
34
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
35

36

37
    RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); // Specify we are using the  // internal clock source
38

39
    RCC_USARTCLKConfig(RCC_USART1CLK_HSI); // I wrote this instruction to  // ensure I am using USART1 with HSI, the apllication wasn't working before neither
40

41
    /* Enable GPIO clock */
42
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
43

44
    /* Enable USART1 Clock */
45
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
46

47

48
    GPIO_Config();
49

50

51
    USART_InitTypeDef USART_InitStructure;
52

53
    /* USART Initialisation for MIDI standard */
54
    USART_InitStructure.USART_BaudRate = 31250; 
55
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
56
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
57
    USART_InitStructure.USART_Parity = USART_Parity_No; 
58
    USART_InitStructure.USART_Mode = USART_Mode_Tx;
59
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
60
    
61
    USART_Init(USART1, &USART_InitStructure);  
62
    
63
    USART_Cmd(USART1, ENABLE);
64
}
65

66
/**
67
* @brief  Configures GPIOS
68
* @param  None
69
* @retval None
70
*/
71
void GPIO_Config(void)
72
{
73
        
74
    GPIO_InitTypeDef GPIO_InitStructure;
75
    
76
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;   
77
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
78
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
79
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
80
    GPIO_Init(GPIOA, &GPIO_InitStructure);
81
    
82
    GPIO_PinAFConfig(GPIOA, GPIO_Pin_2, GPIO_AF_0);
83
    
84
}

main.h :
1
/* Define to prevent recursive inclusion -------------------------------------*/
2
#ifndef __MAIN_H
3
#define __MAIN_H
4

5
/* Includes ------------------------------------------------------------------*/
6
#include "stm32f0xx.h"
7
#include "stm32f0xx_rcc.h"
8
#include "stm32f0xx_it.h"
9
#include "stm32f0xx_gpio.h"
10
#include "stm32f0xx_rtc.h"
11
#include "stm32f0xx_nucleo.h"
12
#include "stm32f0xx_conf.h"
13
#include "stm32f0xx_usart.h"
14

15
/* Exported types ------------------------------------------------------------*/
16
/* Exported constants --------------------------------------------------------*/
17
/* Exported macro ------------------------------------------------------------*/
18
/* Exported functions ------------------------------------------------------- */
19

20

21
void Init(void);
22
void GPIO_Config(void);
23

24

25
#endif /* __MAIN_H */

When I am checking the logic level on PA_2, I find 0. When I am forcing 
PA_2 to 1, it does work.
I would be happy if someone could help me, I am desperate with it.
Thank you in advance.
Attached files:
Guest #3658673
Rate this post
• ▲ useful
▼ not useful
Hey,


Benoit wrote:
> GPIO_PinAFConfig(GPIOA, GPIO_Pin_2, GPIO_AF_0);

STM32F030R8 hasn't mapped USART1 on PA2, please read the datasheet page 
31.
USART1 is available on STM32F030x6 and STM32F030x4 devices only.

Benoit wrote:
> GPIO_PinAFConfig(GPIOA, GPIO_Pin_2, GPIO_AF_0);

I think you have to write GPIO_PinSource2 instead of GPIO_Pin_2.

hope it works
Guest #3660502
Rate this post
• ▲ useful
▼ not useful
You were right, PA_2 is actually connected to USART2 on STM32F030R8. 
Yet, I have tried either PinSource2 with USART1, PinSource2 with USART2, 
and GPIO_Pin_2 with USART2, and it still doesn't work. Is my clock 
initialization okay ? Thank you for your attention.

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.