arduinobitwise-operatorsavratmelavr-gcc

Why I get different result from serial port after this bitwise operation?


I am trying to learn AVR programming with Arduino. But there is an issue when ı try to activate the usart register bits.

UBRR0H = (BRC >> 8);
    UBRR0L = BRC;
    UCSR0B |= (1<<TXEN0);
    UCSR0C |= (1<<UCSZ01) | (1<<UCSZ01) ;
    while(1) //infinite loop
    {
        UDR0 = 'H';
        _delay_ms(1000);
    }

When ı use | operator to activate TXEN and Some bit frames it activates and prints 'H' to my Serial port. That is the result that i want!

UCSR0B = (1<<TXEN0);
UCSR0C = (1<<UCSZ01) | (1<<UCSZ01) ;

when ı use like this, I get 'È' to my serial port!

Why is that? What is the problem?


Solution

  • UCSR0C = (1<<UCSZ01) | (1<<UCSZ01);

    There might be 2 problems here: