/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Usart Polling

Username:     
Password:     
             

Forum

# 1   2012-04-13 11:27:16 Usart Polling

primagen
Member
Registered: 2010-12-07
Posts: 13

Usart Polling

Hi,
why i have to enable USART1->CR1 |= USART_CR1_RXNEIE; for polling
In Example of ST Lib i dont see such thing. I thought for polling i dont need this?

Offline

 

# 2   2012-05-03 09:15:10 Usart Polling

primagen
Member
Registered: 2010-12-07
Posts: 13

Re: Usart Polling

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);
         }
}

Offline

 

Board footer