Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ATMega UART wireless communication

Status
Not open for further replies.

gdonhc

Newbie level 4
Newbie level 4
Joined
Sep 1, 2011
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
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)
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); 
      } 
   } 
}
 

Hi,

If you are using simple serial wired connections then you must have a common ground connection between the two units.

Think you are really saying you want a wireless connection, that can only be achieved by using extra hardware such as bluetooth, IR, Ultrasonic, Xbee etc etc, the choice depends on price, range and if out of line of sight.

Tip for when testing using wires between tx/rx, use a 1K resistor in series to each TX/RX line, so if you connect the lines the wrong way you will not blow your output ports.

TX ------ 1k ----- RX
RX ------- 1K -----TX
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top