AnsweredAssumed Answered

STM32f10x Usart polling problem

Question asked by groma on May 4, 2015
Latest reply on May 5, 2015 by Clive One
Hi,

I have a problem with usart2 with my stm32f10x.
I want to send data using polling and the TXE Flag does not SET and i don't know why.

This is the init of the GPIO Ports.
/** USART2 GPIO Configuration 
  PA2   ------> USART2_TX
  PA3   ------> USART2_RX
  */
 
  /*Enable or disable APB2 peripheral clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
 
  /*Configure GPIO pin : PA */
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; //GPIO_Speed_2MHz;
  GPIO_Init(GPIOA, &GPIO_InitStruct);
 
  /*Configure GPIO pin : PA */
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; //GPIO_Mode_IPU;
  GPIO_Init(GPIOA, &GPIO_InitStruct);
This is the init of the USART 2 and interrupt init for receive
    USART_InitTypeDef       USART_InitStructure;
 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 , ENABLE);
 
USART_Cmd(uart, DISABLE);
 
USART_StructInit(&USART_InitStructure);
USART_InitStructure.USART_BaudRate = 38400;
USART_InitStructure.USART_WordLength = USART_WordLength;
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_Tx | USART_Mode_Rx;
USART_Init(uart, &USART_InitStructure);
 
USART_Cmd(uart, ENABLE);
 
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 6;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);

My putc funktion is
void Uart_putc(USART_TypeDef* uart, char c)
{
    while (USART_GetFlagStatus(uart, USART_FLAG_TXE) == RESET);
    USART_SendData(uart, (uint16_t)c);
}

I can send the first caracter but at the second one it goes into an infinite loope.
I also checked the usart error flags but they never get set. 

I use the same settings for UART5 except another baudrate and there everything is ok.

It would be very fine if somebody could help me :) 

Outcomes