Embed C code for using USART protocol on UNO not working

I’m trying to communicate between two Arduino UNO’s using the USART protocol via a 434 mHz tranciever. The code isn’t working and i can’t seem to understand the issue. Any pointers on why it isn’t working or on how to debug it?
Transmitter
GND >> GND
VCC >> 5v
Data >>tx (01)

Reciever
GND >> GND
VCC >> 5v
Data >> rx(00)

The 13 pin led on the transmitting arduino is continuously on, even if i don’t set it high in my code.
Why is that?
The tx led on the transmitting arduino blinks when connected to laptop via cable, but doesn’t when its powered by a 9v battery. Is the laptop communicating with arduino serially that’s interfering with the transmission?

The Transmitter Code

#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#define BAUD 9600
#define MYUBRR (F_CPU/((16*BAUD)-1))
uint8_t signal_high = 1;
uint8_t signal_low = 0; 
void USART_init(void)
{
  UBRR0L=(uint8_t)MYUBRR;
  UBRR0H=(uint8_t)(MYUBRR>>8);
  UCSR0B |= (1<<TXEN0)|(1<<UCSZ02);
  UCSR0C |= (0<<UMSEL00)|(0<<UMSEL01)|(0<<UPM00)|(0<<UPM01)|(0<<USBS0)|(1<<UCSZ01)|(0<<UCSZ00);
  UCSR0A |=(0<<MPCM0)|(0<<U2X0)|(0<<UPE0)|(0<<DOR0);
}
void USART_transmit(uint8_t data)
{
  while(!(UCSR0A & (1<<UDRE0)))
  ;
  UDR0=data;
}

void setup() {
  
USART_init();
}

void loop() {
USART_transmit( signal_high);
digitalWrite(13,HIGH);
delay(1000);
USART_transmit(signal_low);
digitalWrite(13,LOW);
delay(1000);
}

The Reciever Code

#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#define BAUD 9600
#define MYUBRR (F_CPU)/(16*BAUD)-1

void USART_Init(void)
{
  UBRR0H = (uint8_t)(MYUBRR>>8);
  UBRR0L = (uint8_t)(MYUBRR);
  UCSR0B |= (1<<RXEN0)|(1<<UCSZ02);
  UCSR0C |= (0<<UMSEL00)|(0<<UMSEL01)|(0<<UPM00)|(0<<UPM01)|(0<<USBS0)|(1<<UCSZ01)|(0<<UCSZ00);
  UCSR0A |=(0<<MPCM0)|(0<<U2X0)|(0<<UPE0)|(0<<DOR0);
}
uint8_t USART_recieve(void)
{
  while(!(UCSR0A&(1<<RXC0)))
  ;
  return UDR0;
}
void setup() {
  pinMode(13,OUTPUT);
  USART_Init();
  

}

void loop() {
  
  uint8_t input;
  input = USART_recieve();
  if(input == 0)
  {
    digitalWrite(13,LOW);
    delay(1000);
  }
else
{
  digitalWrite(13,HIGH);
  delay(1000);
}
}

Is there some reason why you are not using the convenient functions in the Arduino IDE?

...R
Serial Input Basics - simple reliable ways to receive data.

Robin2:
Is there some reason why you are not using the convenient functions in the Arduino IDE?

...R

I'm trying to learn embedded development by myself. Hence i'm not using Arduino IDE libraries.

  UCSR0B |= (1<<TXEN0)|(1<<UCSZ02);

UCSR0C |= (0<<UMSEL00)|(0<<UMSEL01)|(0<<UPM00)|(0<<UPM01)|(0<<USBS0)|(1<<UCSZ01)|(0<<UCSZ00);
  UCSR0A |=(0<<MPCM0)|(0<<U2X0)|(0<<UPE0)|(0<<DOR0);






void setup() {
  
USART_init();
}

void loop() {

If you’re going to use the Arduino IDE, and the setup() and loop() constructs, that means that the Arduino “init” function is going to be called, and it’s going to initialize the uart as appropriate for the Arduino libraries.
For certain subsets of the uart functionality, you MIGHT be able to undo that configuration, but you’ll have to do full writes to the uart configuration registers instead of or-ing in new bits (“UCSR0B |= (1<<RXEN0)|(1<<UCSZ02);”) And you won’t be able to use interrupts, since the Arduino code already defines the ISR vectors for the UART.

You could also avoid the Arduino init code by defining main() in your sketch instead of setup an loop, but I think you’ll still have the ISR problem.

If you really want to “learn embedded development without the Arduino libraries”, you shouldn’t use the IDE, either. “Atmel Studio” is probably the preferred IDE. Or you can use your favorite editor and command-line utilities. (Both of these less-than-tasty alternatives ARE part of “embedded development.”)

This might help: install-avr-tools | Hackaday.io

cghgy:
I'm trying to learn embedded development by myself.

You can by using the Arduino IDE and reading through the IDE functions as well :wink:

cghgy:
Hence i'm not using Arduino IDE libraries.

Then you're on the wrong forum :wink:

Then you're on the wrong forum

There is avr-freaks: https://www.avrfreaks.net/

The 13 pin led on the transmitting arduino is continuously on, even if i don't set it high in my code.
Why is that?

On recent Unos, the pin13 LED is driven through a "driver" op-amp, which means that the LED state when the AVR pin is "floating" can be ... rather random. Does it go out if you set the pin to output and LOW? (In general, the common practice of leaving unused pins configured as inputs, and floating, is not good.)

The tx led on the transmitting arduino blinks when connected to laptop via cable, but doesn't when its powered by a 9v battery. Is the laptop communicating with arduino serially that's interfering with the transmission?

I believe that the tx led is driven by the USB/Serial converter chip, and it may not get illuminated if there is no USB connection...

septillion:
Then you're on the wrong forum :wink:

That was in my mind when I wrote Reply #1

...R