cancel
Showing results for 
Search instead for 
Did you mean: 

USART polling vs Interrupt

Niks
Associate II
Posted on August 08, 2016 at 14:12

Hi,

I have implemented simple USART polling and interrupt method.

// main function

while(1)

{

 send_data();

//usartSendString(USART1,array,34);

GPIOF->ODR ^= GPIO_Pin_10;

 

}

///simple USART polling function

void usartSendString(USART_TypeDef *USARTx,uint8_t *data,int32_t length)

{

while(length > 0)

{

while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

USART_SendData(USART1,data);

data++;

length--;

}

}

When i send data using polling method, gpio high/low period is around 6ms and when i send it using interrupt method it's high/low period 150us.

send_data function sends the same number of bytes as sent in usartSendString() function .

why there is delay in polling method???

4 REPLIES 4
Posted on August 08, 2016 at 14:53

why there is delay in polling method???

Well as you don't show the interrupt implementation, I'd assume it is faster because the send routine should buffer the data and return *immediately* instead of waiting for all the bytes to go over the wire.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Niks
Associate II
Posted on August 08, 2016 at 16:02

In ISR i am just checking for TXE flag and sending the data over serial line.

and in

void send_data()

{

int i = 0;

  while(i < 34)

{

send_char(i);

}

}

void send_char(char data)

  tx_buff[tx_index_wr++]=data;

USART_ITConfig(USART1, USART_IT_TXE, DISABLE);

tx_count++;

USART_ITConfig(USART1, USART_IT_TXE, ENABLE);

if(tx_index_wr == TX_BUFF_SIZE)

tx_index_wr = 0;

}

Niks
Associate II
Posted on August 08, 2016 at 16:05

The main sends the entire array and only then it toggles the GPIO port pin.

in polling just byte is put in DR register and waited for TXE flag to be SET.

While in Interrupt just byte is put in DR register.

In any manner time should be the same. But  i am not getting the same time period, why???

Posted on August 08, 2016 at 16:31

In any manner time should be the same. But  i am not getting the same time period, why???

This perhaps might be true if you had the first clue what you are doing, but simply enabling and disabling interrupts and resetting the buffer endlessly in a loop doesn't achieve this.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..