AnsweredAssumed Answered

STM32F105 USART2's DR register not working

Question asked by brunengo.maxime on Jul 18, 2014
Latest reply on Jul 21, 2014 by brunengo.maxime
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,

Outcomes