ok i switch from polling to interrupt method.
below the code. In init i enabled RX interrupt.And set priority to 2.
void USART2_handler(void)
{
if (USART2->SR & USART_SR_RXNE)
{
if(uart2_input_handler != NULL)
{
uart2_input_handler((int)(USART2->DR & 0xFF));/*Bytewise*/
}
}
if ((USART2->SR & USART_SR_TXE) !=0)
{
USART2->CR1 ^= USART_CR1_TXEIE;
}
}
void u2_putchar(char c)
{
USART2->DR = (c & 0xFF);
USART2->CR1 |= USART_CR1_TXEIE;
}
It works but it also works with below if i disable TX interrupt for all time and doesnt look for TXE flag in usart2 handler.
void USART2_handler(void)
{
if (USART2->SR & USART_SR_RXNE)
{
if(uart2_input_handler != NULL)
{
uart2_input_handler((int)(USART2->DR & 0xFF));/*Bytewise*/
}
}
}
void u2_putchar(char c)
{
if ((USART2->SR & USART_SR_TXE) !=0)
{
USART2->DR = (c & 0xFF);
}
}