UART programming problem

i’m trying to send data from a Atmega32 to a Atmega 328. There is a button and a Led on transmitting microcontroller(Atmega32), the Led toggles each time button is pressed. Which is working without any issues( code below). My aim is to send bits from the Atmega32 to Atmega 328 so that Led on the Atmega328 will toggle in sync with the Led on Atmega 32 when the button in Atmega32 is pressed.

Atmega32 code

#include <avr/io.h>
int main(void)
{
 
//set led for output and set it to low(0V). 
 DDRB |= (1 << PINB1);
 PORTB &= ~(1 << PINB1);

//set but for input and set it high.
 DDRB &= ~(1 << PINB0);
 PORTB |= (1 << PINB0); 
 
 // initialize debouncing variables
 int pressed = 0;
 int pressed_confidance_level = 0;
 int released_confidance_level = 0;
 
 // communication uart specifications
 int UBRRH_Value = 25;
 UBRRH =(unsigned char)(UBRRH_Value >> 8);
 UBRRL = (unsigned char) UBRRH_Value;
 UCSRB = (1 << RXEN) | (1 << TXEN);
 UCSRC = (1 << USBS) | (3 << UCSZ0);

    while(1)
    {
        if(bit_is_clear(PINB , 0))// if button is pressed.
 {
 pressed_confidance_level++; //pressed_confidance_level is increasing..
 released_confidance_level = 0;
 if (pressed_confidance_level >100)// after 100 times iteration of while loop, while button is pressed.
 {  //
 if (pressed == 0)  //
 {  //
 pressed = 1;  //
 PORTB ^= (1 << PINB1);
 while(!(UCSRA & (1 << UDRE)));
 UDR = 0b11110000; //
 }  //
 pressed_confidance_level = 0; //
 }
 
 }
 else
 {
 released_confidance_level++;
 pressed_confidance_level = 0;
 if (released_confidance_level > 100)
 {
 pressed = 0;
 released_confidance_level = 0;
 }
    }
}
}

the code below is for the receiving (Atmega328p) microcontroller. It compiles and flashed in to the microcontroller without any problem except for “cannot set sck peroid” warning. But the Led on Atmega328p is not toggleing in sync with the Atmega32 Led.

#include <avr/io.h>

int main(void)
{
 // intitialize LED and USART
 
 DDRB |= (1 << PINB0); 
 
 DDRD = 0b11111111;
 PORTD = 0b00000000;
 
 PORTD = 0b00100000;
 
 
 int UBRRH_Value = 25;
 UBRR0H = (unsigned char )(UBRRH_Value >> 8);
 UBRR0L = (unsigned char )UBRRH_Value;
 UCSR0B = (1 << RXEN0) | (1 << TXEN0);
 UCSR0C = (1 << USBS0) | (3 << UCSZ00);
 
 
 unsigned char recieveData;
    while(1)
    {
 while(!(UCSR0A & (1 << RXC0)));
 recieveData = UDR0;
 if (recieveData == 0b11110000) PORTB |= (1 << PINB0); 
 
 
    }
}

what’s the issue with the code.?

Thanks.

For ATmega32:

 UCSRC = (1 << USBS) | (3 << UCSZ0);

Doesn’t the m32 have some different procedure related to the bitrate divisor having one of its register locations shared with something else?

(yes. From the datasheet:

When the function writes to the UCSRC Register, the URSEL bit (MSB) must be set due to the sharing of I/O location by UBRRH and UCSRC.

)