gdonhc
Newbie level 4
- Joined
- Sep 1, 2011
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,318
Hi all,
I'm trying to build a remote controller using ATMEG8A uC, to send signals to ATMega32A uC.
As this is my first time using UART, I first connected Tx and RX using a wire and tested LED on/ off function using following codes for Tx (8a) and RX(32a)uCs.(with two separate power supplies)
The problem is, this works fine only if the two uCs have a common Ground. As my final goal is to build a remote controller,it cannot have a common ground.
Please tell me what I have missed.
Transmitter (ATMega8)
Receiver (ATMega32)
I'm trying to build a remote controller using ATMEG8A uC, to send signals to ATMega32A uC.
As this is my first time using UART, I first connected Tx and RX using a wire and tested LED on/ off function using following codes for Tx (8a) and RX(32a)uCs.(with two separate power supplies)
The problem is, this works fine only if the two uCs have a common Ground. As my final goal is to build a remote controller,it cannot have a common ground.
Please tell me what I have missed.
Transmitter (ATMega8)
Code:
#include <avr/io.h>
int main(void)
{
//LED
DDRB|=(1<<PINB0);
PORTB&= ~(1<<PINB0);
//button
DDRB&=(1<<PINB1);
PORTB|= (1<<PINB1);
int UBRR_value = 25;
UBRRH = (unsigned char) (UBRR_value >> 8);
UBRRL = (unsigned char) UBRR_value;
UCSRB|= 1<< TXEN;
UCSRC = (1<<USBS)|(3<<UCSZ0)|(1 << URSEL);
while(1)
{
if(bit_is_clear(PINB,1))
{
PORTB^= (1<<PINB0);
while (! (UCSRA & (1 << UDRE)) );
UDR = 0b00000011;
}
}
}
Receiver (ATMega32)
Code:
#include <avr/io.h>
int main(void)
{
DDRB|=(1<<PINB0);
int UBRR_value = 25;
UBRRH = (unsigned char) (UBRR_value >> 8);
UBRRL = (unsigned char) UBRR_value;
UCSRB|= 1<< RXEN;
UCSRC = (1<<USBS)|(3<<UCSZ0)|(1<<URSEL);
unsigned char receiveData;
while(1)
{
while (! (UCSRA & (1 << RXC)) );
receiveData = UDR;
if(receiveData==0b00000011)
{
PORTB^= (1<<PINB0);
}
}
}