2016-08-08 05:12 AM
Hi,
I have implemented simple USART polling and interrupt method.// main functionwhile(1) { send_data(); //usartSendString(USART1,array,34); GPIOF->ODR ^= GPIO_Pin_10; }///simple USART polling functionvoid 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???2016-08-08 05:53 AM
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.2016-08-08 07:02 AM
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;}2016-08-08 07:05 AM
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???2016-08-08 07:31 AM
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.