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?