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.

Cannot receive data from PC serially connected to ATMEGA8

Status
Not open for further replies.

yviswanathbe

Full Member level 4
Joined
Jun 14, 2007
Messages
221
Helped
10
Reputation
20
Reaction score
6
Trophy points
1,298
Activity points
3,066
Hi,
I am working on AVR Atmega8 Microcontroller.
I am using Code Vision AVR Compiler.
I am facing problem in serial communication.
I am able transmit data to the PC but i am not able to receive data from the PC.

What could be the problem?
Please suggest me something.

Thanks& Regards,
Y.Viswanath.
 

codevision communication error

One possibility is that problem is in the configuration of your serial port, Check if the 'receiver' and 'receive complete interrupt' both are enabled.
 

codevision serial communication tutorial

Hi,
here are my USART configuration details:

Code:
	UCSRA=0x00;
	UCSRB=0x18;
	UCSRC=0x86;
	UBRRH=0x00;
	UBRRL=0x19;

n
here are the functions i have used for Tx and Rx

void serial_send(unsigned char dat)
{
       while((UCSRA & 0x20)==0x00); //wait for UDRE flag
       UDR=dat;
       while((UCSRA & 0x40)==0x00); //wait for TXC flag.
}
unsigned char serial_read()
{
	if(!UCSRA.7)
	{
		return UDR; 
	} 
}
i think i have everything correct.

Please let me know if i am doing anything wrong?

Thanks,
Y.Viswanath

Added after 11 minutes:

HI,
Now i am able to receive the data as well as transmit the data.
Problem is with RX function.

Here is updated code.
Code:
unsigned char serial_read()
{
	while((UCSRA & 0x80)==0x00);
	{
		return UDR; 
	} 
}
 

bad isr interrupt atmega8

could any body send me some sample code for serial communication using ISR.
using codevision AVR.
 

+codevision +txc

hmm, what kind of sample do you want??
here is one of multiple bytes tx to micro.. take a look.

Code:
data = receive();
switch (state){
    case 0: // wait for sync
        if(data == SYNC) state = 1;
        break;

    case 1: // got sync, get byte count
        byte_count = data;
        counter = 0;
        checksum = 0;
        state = 2;				
        break;

    case 2:	// get data
        buffer[counter] = data;
        checksum ^= data;
        counter++;
        byte_count--;
        if(byte_count == 0) state = 3;
        break;
     
    case 3: // grab checksum
        if(checksum == data) 
        {
	// packet is valid
        }
        else
        {
	// packet is bad
        }
        state = 0;
        break;
}

Added after 1 minutes:

oopss, sorry.. my bad.. but who knows you need it someday..:D
 

Re: ATMEGA8 help????

Hi,
Thanks for sharing the code.

I need how to configure Interrupt Service Routine(ISR) for Serial Communication.

I have used CodeVisionAVR for sample code,but it is giving lots of code for ISR.i.e.,error frame checkingh,parity checking.
Do i need to do all the above to interact with my microcontroller from PC.

please post some tutorials on AVR ISR programming.

Thanks,
Viswanath.
 

Re: ATMEGA8 help????

Hai

Check out the tutorial at avrfreaks.net

Nandhu
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top