Serial communication between 2 Arduino Uno using registers

Hello! I’m working on a school project where I need to use 2 Arduino Uno boards, one of them is “emulating” a sensor(I have buttons that can change the float value) and another one that is connected to a lcd display.

The thing is that I need to transfer that value between the 2 boards using serial communication, without using function(like Serial.write(), read(), available() ).

For the sake of simplification I converted that float to a string and I used this code to send it:

#define BAUD 9600
#define MYUBRR F_CPU/16/BAUD-1


void USART_Init(unsigned int ubrr)
{
  UBRR0H=(unsigned char)(ubrr>>8);
  UBRR0L=(unsigned char)ubrr;
  UCSR0B=(1<<RXEN0)|(1<<TXEN0);
  UCSR0C=(1<<USBS0)|(3<<UCSZ00);
}

void USART_Transmit(unsigned char data)
{
  while(!(UCSR0A&(1<<UDRE0)));
  UDR0=data;
}

void SendString(char *StringPtr)
{
  while(*StringPtr !=0x00)
  {
    USART_Transmit(*StringPtr);
    StringPtr++;
  }
}

void setup()
{
    USART_Init(MYUBRR);
}

void loop()
{
 SendString("123456");
  delay(1000);
}

It’s all cool I guess, on the first serial monitor there is “123456” every second, but the problem is that I have no idea how to receive,store and show the value on LCD using the second Arduino. I know that I need to use something like:

unsigned char USART_Receive(void)
{
  while(!(UCSR0A&(1<<RXC0)))

  return UDR0;
}

since the content is in the UDR0 register, and just store those chars in a string, but I simply can’t do it, either I print just 0’s on my display or I am able to get only the first char(s) of the string, or I get blank spaces or invalid chars like that white square or y with dots or nothing happens at all.

I wasn’t able to find anything useful online, I found only that if I want to use and lcd on the second Arduino I should not use that USART_Receive(void) and use an interrupt instead(witch is also super hard).

Can you show me how to make it work?

truewarlock:
The thing is that I need to transfer that value between the 2 boards using serial communication, without using function(like Serial.write(), read(), available() ).

Why?

If you want to learn how to use the UART directly then there is example code in the Atmega 328 datasheet.

If you want to avoid using the Rx and Tx pins (so they can be used for uploading programs and for debug messages) then I suggest you use I2C to communicate between the Arduinos. This I2C Tutorial should get you started.

...R

The Arduino Uno (ATmega328P) does not really have a hardware buffer for the serial input. As far as I remember, it has a shift register for incoming data and one byte as buffer.

At 9600 that is a character every millisecond. That means your other code must be executed within 1 ms when no interrupts are used. I doubt if 1 ms is enough, so you probably need an interrupt routine for the RX data.

There are many examples, too many.
For example at Projects | AVR Freaks.
Search for uart and usart.