AnsweredAssumed Answered

USART2 problem with cmsis library

Question asked by mohamadi.parisa on Sep 7, 2016
Latest reply on Sep 8, 2016 by FTITI.Walid
Hello
Here is my code shown below.
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_usart.h"
 
void delay()
{
    int i,j;
    for(i=0;i<10000;i++)
    for(j=0;j<100;j++);
}
 
GPIO_InitTypeDef GPIOStruc;
USART_InitTypeDef USAR;
int main(){
 
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
     
        //PD5
    GPIOStruc.GPIO_Mode=GPIO_Mode_AF_PP ;
    GPIOStruc.GPIO_Speed=GPIO_Speed_50MHz;
    GPIOStruc.GPIO_Pin=GPIO_Pin_5;
    GPIO_Init(GPIOD,&GPIOStruc);
     
    //PD6
    GPIOStruc.GPIO_Mode=GPIO_Mode_IN_FLOATING ;
    GPIOStruc.GPIO_Speed=GPIO_Speed_50MHz;
    GPIOStruc.GPIO_Pin=GPIO_Pin_6;
    GPIO_Init(GPIOD,&GPIOStruc);
     
    GPIO_PinRemapConfig(GPIO_Remap_USART2,ENABLE);
     
    USAR.USART_BaudRate=9600;
    USAR.USART_StopBits=USART_StopBits_1;
    USAR.USART_WordLength=USART_WordLength_8b;
    USAR.USART_Parity=USART_Parity_No ;
    USAR.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
    USART_Init(USART2,&USAR);
    USART_Cmd(USART2,ENABLE);
     
     
    RCC->APB2ENR=(1<<4);
    GPIOC->CRL=(2<< 8);
    GPIOC->BSRR=(1<<2);
    while(1)
    {
USART_SendData(USART2, 'X');
        delay();
    }
}

I want to send and receive data via PD5 and PD6 (remap these pins) but it doesn't work properly , what is my mistake?

Outcomes