Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
himel1842
PostPosted: Jun 25, 2012 - 06:00 PM
Rookie


Joined: Oct 28, 2011
Posts: 26


Quote:
Did you write the code to turn on the LEDs?

Yes, I wrote the code.
Code:
 while (1) {
      USART0WriteChar(data);
      data = USART0ReadChar();
      if (data != sentchar) {
        DDRB =0xFF;
      PORTB=0xFF; // turn on good led
     } else {
         DDRC =0xFF;
       PORTC=0xFF;// turn on bad led
      }
      _delay_ms(500);
   
   } 


I can see the output in proteus, still not in real hardware.Tried with common ground as well. But couldn't find where is the problem.
 
 View user's profile Send private message  
Reply with quote Back to top
larryvc
PostPosted: Jun 25, 2012 - 06:14 PM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

Have you programmed the fuses on the chips to use the 8MHz crystals? Do you have a schematic of your board?

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
himel1842
PostPosted: Jun 26, 2012 - 02:57 PM
Rookie


Joined: Oct 28, 2011
Posts: 26


Quote:
Have you programmed the fuses on the chips to use the 8MHz crystals?

Fuse setup is shown in the attached file.
Quote:
Do you have a schematic of your board?

I am using two breadboard for master and slave. Proteus schematic and connection is shown in the attached file.
 
 View user's profile Send private message  
Reply with quote Back to top
himel1842
PostPosted: Jul 30, 2012 - 04:13 PM
Rookie


Joined: Oct 28, 2011
Posts: 26


Quote:
Typically, you would use a second UART. Somewhere. There ARE AVRs with several UARTS (some with 4, even).


I can get somthing out of my 2nd USART but problem is this is not always same what I transmit. If I contnously transmit 'A' from the transmitter I dont always get A in the receiver TX port. I checked this by Using interface to PC. Anyone has any idea why its happening?
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Jul 30, 2012 - 04:32 PM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18513
Location: Lund, Sweden

Quote:
Anyone has any idea why its happening?

Present a minimal program that builds, runs and displays the problem.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
himel1842
PostPosted: Aug 07, 2012 - 06:19 PM
Rookie


Joined: Oct 28, 2011
Posts: 26


Quote:
Present a minimal program that builds, runs and displays the problem.


I am sending A, but don't receive A all the time.I am interfacing laptop with Receiver Tx , and seeing the output using Realterm. If I see the output in Uint format I get 208,11 and sometimes 65 which is transmitted character A.

My question is why I get 208 and 11?

Code for TX
Code:
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
void USARTInit(int ubrr_value);
void USARTWriteChar(char data);

#ifndef BAUDRATE
#define BAUDRATE 38400
#endif
#define BAUD_PRESCALE (((F_CPU/(BAUDRATE*16UL)))-1)
int main(void)
{
   
   USARTInit(BAUD_PRESCALE);
   
    while(1)
    {
      USARTWriteChar('A'); // send the data to USART Tx for transmission
      
      
    }
   
}

void USARTInit(int ubrr_value)
{
   //Set Baud rate
   UBRR0 = ubrr_value;
   //Enable The receiver and transmitter
   UCSR0B=(1<<RXEN0)|(1<<TXEN0);
 
   UCSR0C=(1<<USBS0)|(3<<UCSZ00);

}


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


Code for Rx
Code:
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>

void USARTInit(int ubrr_value);
char USARTReadChar();
void USARTWriteChar( char data);

#ifndef BAUDRATE
#define BAUDRATE 38400
#endif
#define BAUD_PRESCALE (((F_CPU/(BAUDRATE*16UL)))-1)

int main()
{
   char data;
   USARTInit(BAUD_PRESCALE);
   while(1)
   {
      data=USARTReadChar();
      
      USARTWriteChar(data);
      
      
   }      
   
}


void USARTInit(int ubrr_value)
{
   //Set Baud rate
   UBRR0 = ubrr_value;
   UBRR1 = ubrr_value;
   //Enable The receiver and transmitter
   UCSR0B=(1<<RXEN0)|(1<<TXEN0);
   UCSR0C=(1<<USBS0)|(3<<UCSZ00);
     

}

char USARTReadChar()
{
   
   while(!(UCSR0A & (1<<RXC0)))
   {
     
   }
    return UDR0;
}

void USARTWriteChar( char data)
{
   while(!(UCSR0A & (1<<UDRE0)))
   {
      
   }
   UDR0=data;
}
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits