I need to transfer a string between 2 Arduino Uno, using serial communication without functions(just manipulating registers, such as UDR0).
I am able to send a string using
#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);
}
but I have no idea how to copy the content of the UDR0 register at the other end. The function should be something like:
unsigned char USART_Receive(void)
{
while(!(UCSR0A&(1<<RXC0)))
return UDR0;
}
But I don't know how to actually use it; I need to save all those chars from the serial to a string, then show the string on a LCD connected to the second Arduino Uno, but every time when I attempt to receive more that one char it's all working very bad(blank spaces, a lot of zeros, invalid characters).
I read that if I have an LCD connected to the second arduino, it's much better to not use the USART_Receive() function, and implement it as an interrupt, but I don't know how to do that either.
Do you have any idea how to transfer the string to the other Arduino?