-1

this piece of code in running on ATmega2560, so what is the difference between these two:

while(UCSR0A & 0b00100000 == 0);  // check UDRE0 bit if it is 1

and:

loop_until_bit_is_set(UCSR0A, UDRE0);

as you can see this is for UART transmission, but if i use the first one I could't get desired output on terminal, for example if i do printf("Hello world\n"); the actual terminal display is: HeHeHe....... However the latter one works. You can find this piece of code in stdio.h.

zrs5532
  • 1
  • 2

1 Answers1

3

== has higher priority than &; also, no need to check for == 0 - you should try

while(!(UCSR0A & 0b00100000));

or rather, using bit macro

while(!(UCSR0A & _BV(UDRE0)));

instead.

Ruudje
  • 31
  • 1