cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F105 USART2's DR register not working

maxime
Associate II
Posted on July 18, 2014 at 13:48

Hi all,

I'm trying to use the USART2 on the STM32F105CL to communicate with an hyper-terminal but unfortunatly, the hyper-terminal is not receiving anything. Even with a very simple code.

/* Includes ------------------------------------------------------------------*/

#include <stdio.h>

#include <string.h>

#include ''stm32f10x.h''

#include ''stm32f10x_gpio.h''

#include ''stm32f10x_rcc.h''

#include ''stm32f10x_usart.h''

#include ''leds.h''

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/

/* Private functions ---------------------------------------------------------*/

int main(void)

{

LED_Init();

/* ************************************************************/

USART_InitTypeDef USART_InitStructure;

GPIO_InitTypeDef GPIO_InitStructure;

/* Enable GPIO clock */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);

/* Enable USART clock */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);

//Configure USART2 pins:  Rx and Tx ----------------------------

GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_2;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_3;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOA, &GPIO_InitStructure);

USART_InitStructure.USART_BaudRate = 57600;

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(USART2, &USART_InitStructure);

USART_Cmd(USART2,ENABLE);

/* ********************************************/

while (1)

{

for(int i=0;i<100000;i++)

{

LED_On();

}

for(int i=0;i<100000;i++)

{

LED_Off();

}

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

USART_SendData(USART2,'a');

while(USART_GetFlagStatus(USART2,USART_FLAG_TXE) == RESET){};

}

return 0;

}

Sombody has any clue ?

Thanks,
15 REPLIES 15
maxime
Associate II
Posted on July 18, 2014 at 17:05

So,

Tool chain : gcc

Library's version : V3.5.0

maxime
Associate II
Posted on July 18, 2014 at 17:08

Sorry, the RESET Value is 0

''typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;''

Posted on July 18, 2014 at 17:23

Why are you remapping the pins? PA2/3 are the default exit points for USART2, PD5/6 are the remapped ones.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on July 18, 2014 at 17:41

Which version of GNU/GCC? Who's package? As you mentioned HyperTerminal, assuming a Windows platform.

Attached is a USART2 demo, I would have added LEDs but neither your board, or configuration has been expressed. The .HEX should output a stream of 'a' characters at 57600 8N1

________________

Attachments :

USART2-CL.hex : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0qo&d=%2Fa%2F0X0000000bef%2F0GcopP7AvKDV8hLcealkR17XvyVyR_xtY9ODL6qQEVk&asPdf=false
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
maxime
Associate II
Posted on July 21, 2014 at 08:52

YOU... ARE..... SO.. GENIOUS !!!

The problem was the remapping. I comment the line and it works (once...).

After one success, i've got a infinite loop when I wait for the TXE flag to be SET.

maxime
Associate II
Posted on July 21, 2014 at 09:54

Funny, the problem seems to be the STlink V2.

When I put the power on the STM32f105, so he runs the last code flashed on it, it works...

When I pass through the Eclipses debugger, I have the infinite loop.

Don't know why but w/e.