Forum Discussion
Altera_Forum
Honored Contributor
21 years agoproblem of "if" condition
I wrote a program to process data from PC through uart, but there is something wrong.
<div class='quotetop'>QUOTE </div> --- Quote Start --- main() { ...... init_uart0(); ...... while(1) { if(uart0_rbuf_out_cnt != uart0_rbuf_in_cnt ) { ...... } } }[/b] --- Quote End --- I receive data in uart0_ISR(), if there is one new byte, at first put it into the uart0_rbuf, and then the uart0_rbuf_in_cnt add 1. The problem is when (uart0_rbuf_out_cnt != uart0_rbuf_in_cnt ) is true, it can not go into the program to process the data. What's the matter?Thanks.2 Replies
- Altera_Forum
Honored Contributor
Hi,
define uart0_rbuf_out_cnt and uart0_rbuf_in_cnt variable as volatile, for example: volatile int uart0_rbuf_out_cnt if not, the compiler optimize these variables because they aren't managed in the main program... - Altera_Forum
Honored Contributor
http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/tongue.gif Thanks,Soin,I'll try.