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
riddhesh
PostPosted: Jan 27, 2011 - 03:47 AM
Rookie


Joined: Oct 21, 2010
Posts: 43


Dear Freaks,
Please find the below code, its echo bis not received.
I am using brayns terminal.
->baud 9600
->crystal 7.3728M
->prescaler 47
help me detecting BUG in the below code
Code:

#include <avr/io.h>
#include <avr/interrupt.h>
//#ifdef F_CPU 7372800 // Set CPU speed to 7.37 MHz
#define BAUD_PRESCALE 47 // prescaller set to 9600 baud
//endif
//unsigned short int rxByte=0;////// Define Global Variable
/////////////////////////////////////////////////////
void USART_Init()
{
      //Enable Transmitter and Receiver and Interrupt on receive complete

      UCSR0B=(1<<RXEN0)|(1<<TXEN0);//|(1<<RXCIE0);

      //Set data frame format: asynchronous mode,no parity, 1 stop bit, 8 bit size

      UCSR0C=(1<<UMSEL00)|(1<<UCSZ01)|(1<<UCSZ00)|(0<<UMSEL01)|(0<<UPM01)|(0<<UPM00)|(0<<USBS0)|(0<<UCSZ02);   

      
      //Set baud rate

      UBRR0H=(BAUD_PRESCALE>>8);   //high byte
      UBRR0L=BAUD_PRESCALE;      //low byte
}
///////////////////////////////////////////////////////////////////
//ISR(USART_RX_vect)
//{
//}
//////////////////////////////////////////////////////////
int main (void)
{
    DDRB=0xff;
   PORTB=0x00;
   unsigned char rxByte;
   USART_Init();
for(;; )
   {
   
   while ((UCSR0A & (1 << RXC0)) == 0) {}; // Do nothing until transmission complete flag set
   //sei();
   rxByte = UDR0; // Fetch the recieved byte value into the variable "ByteReceived"
   
   while ((UCSR0A & (1 << TXC0)) == 0) {};
   UDR0= rxByte;
      }
}



Freaks Please Help!!! Smile
 
 View user's profile Send private message  
Reply with quote Back to top
glitch
PostPosted: Jan 27, 2011 - 03:54 AM
Raving lunatic


Joined: Jan 12, 2002
Posts: 7834
Location: Canada

how have you verified you are actually operating at 7.3728MHz?

Try sending a constant stream of 'U' characeters. Measure the resultant frequency on the TX pin. The frequency will be 1/2 the baud rate.

Also don't wait on TXC, instead wait on UDRE when transmitting. [TXC is an edge triggered flag, UDRE is a level triggered one]
 
 View user's profile Send private message  
Reply with quote Back to top
riddhesh
PostPosted: Jan 27, 2011 - 07:11 AM
Rookie


Joined: Oct 21, 2010
Posts: 43


Dear glitch,

I ddnt got your point, please en-light me more.
I have connected crystal of 7.3728M.

Freaks Please Help!!! Smile
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jan 27, 2011 - 08:05 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 71915
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

I have connected crystal of 7.3728M

Merely connecting it is not sufficient to activate it - you must also program the CKSEL fuses. Hence the reason glitch suggested you verify that you have performed that activation correctly by using a scope/frequency meter or perhaps a program that simply flashes an LED at a known rate based on a 7.3M assumption.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
riddhesh
PostPosted: Jan 28, 2011 - 10:57 AM
Rookie


Joined: Oct 21, 2010
Posts: 43


Dear Clawson & Glitch,
I dont know much about the above CKSEL fuses, please en-light me more.

Freaks Please help! Smile
 
 View user's profile Send private message  
Reply with quote Back to top
MBedder
PostPosted: Jan 28, 2011 - 11:39 AM
Raving lunatic


Joined: Nov 02, 2009
Posts: 3239
Location: Zelenograd, Russia

En-lighting.

_________________
Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.
 
 View user's profile Send private message  
Reply with quote Back to top
riddhesh
PostPosted: Feb 17, 2011 - 08:42 AM
Rookie


Joined: Oct 21, 2010
Posts: 43


thank you freaks Smile
now m able to send and receive data from PC to Uc and from Uc to PC.
I am using interrupts for receiving data.
I want to ask one more question:-
Is UART point to point protocol or point to multi point protocol?

Freaks Please Help.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Feb 17, 2011 - 09:04 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 71915
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

Is UART point to point protocol or point to multi point protocol?

The UART in an AVR can do both. Usually it is point to point but there is a mode called MPCM ("Multi Processor Communication Mode" - see the datasheet) where a ninth bit is sent in each frame. It is used to say "the next 8 bits are either data or an address". All the "listners" listen for address frames and only when they see the address they've been assigned do they then process the following data. If they have not been addressed (or a new address frame that is not for them is used) then they ignore subsequent data.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
riddhesh
PostPosted: Feb 21, 2011 - 05:42 AM
Rookie


Joined: Oct 21, 2010
Posts: 43


Thanks Clawson.
I will workout on MPCM in nearest future.
 
 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