Must add a delay function between two “io_write()” functions?

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I put the two functions together. The result is that the first “io_write()”  function will execute correctly, but the second function will sometimes not display.like this

Usart error

When I add a delay function between them, the situation will be solved, but if the delay time is short(like 50ms), the problem will still occur.

 

I think that “usart_async_is_tx_empty(&USART_0)”  is not working properly, in fact, the transmission does not end.

Can anyone tell me why this is?

Thank you!

 

This is my main() code:


int main(void)
{
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();
	usart_async_register_callback(&USART_0, USART_ASYNC_RXC_CB, rx_cb_USART_0);
	usart_async_enable(&USART_0);
	/* Replace with your application code */
	while (1) {
		    /* First write */
			io_write(&USART_0.io, (uint8_t *)"This is First\n", 14);
			while(usart_async_is_tx_empty(&USART_0)!=1);  // waiting the tx is over
			//delay_ms(500); // Add this,the problem may be solved
			/* Second write */
			io_write(&USART_0.io, (uint8_t *)"This is Second\n", 15);
			while(usart_async_is_tx_empty(&USART_0)!=1);  // waiting the tx is over
	}
}

And this is the Atmel Start settings

Usart Atmel Start setting

This topic has a solution.

Just code

Last Edited: Mon. Nov 25, 2019 - 06:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am a Chinese boy, my English is not good, all the dialogues above are google translation,please accept my apology for my poor English。

I am a newcomer to Atmel, I used to use STM32 before.

Just code

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

It may be that

usart_async_is_tx_empty(&USART_0)

is only on a per character basis, not buffer. If you make a loop for "This is First\n" sending one character at a time, it will work.

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for your reply, I will test it on Monday when I go to work.

Just code

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It works fine.you are right,Thanks!

 

Just code