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.

[SOLVED] RS-232 Problem in ATmega32

Status
Not open for further replies.

Briez

Member level 5
Joined
Nov 30, 2012
Messages
83
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Activity points
1,835
hi,

I am interfacing Atmega32 with PC via RS232 Protocol. I have made a hardware with max232 and made simple echo back received program, but i am facing a problem in that.

When i send character 'A' from PC it echo backs with Garbage character. I am using 4MHZ external crystal.

What should be the problem?

I am attaching my code below,

Code:
#define F_CPU 4000000UL
#include<avr/io.h>
#include<avr/interrupt.h>

#define USART_BAUDRATE 9600
#define BAUD_PRESCALE ((( F_CPU / ( USART_BAUDRATE * 16UL))) - 1)

int main(void)
{
UCSRB |= (1 << RXEN ) | (1 << TXEN ); // Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL ) | (1 << UCSZ0 ) | (1 << UCSZ1 ); // Use 8- bit character sizes

UBRRH = ( BAUD_PRESCALE >> 8); // Load upper 8- bits of the baud rate value into the high byte of the UBRR register
UBRRL = BAUD_PRESCALE ; // Load lower 8- bits of the baud rate value into the low byte of the UBRR register

UCSRB |= (1 << RXCIE ); // Enable the USART Recieve Complete interrupt ( USART_RXC )

sei (); // Enable the Global Interrupt Enable flag so that interrupts can be processed

	for (;;) // Loop forever
	{
		// Do nothing - echoing is handled by the ISR instead of in the main loop
	}

}
ISR (USART_RXC_vect)
{
char ReceivedByte ;
ReceivedByte = UDR ; // Fetch the received byte value into the variable " ByteReceived "
UDR = ReceivedByte ; // Echo back the received byte back to the computer
}
 

Try to implement only transmission separate by disabling reception. Once it work then Only use Reception from PC to At mega. This indicate is hardware or software or both part problem
 

I have checked both separately....

But still there is some problem.

I have simulated this code on simulator and it shows me working an Okay. But it doesn't work into my hardware.
 

if simulator shows working then check IC MAX 232 Capacitor , ur TXD, RXD pin & last but most important ur power supply
 

My VCC pin shows 4.53V
Ground is connected with 0V pin.

Capacitor used is 1uf/63V and its connection is ok.

RXD TXD pins are connected to RX TX pins of ucontroller.

I am Using IC MAX232CPE from MAXIM.

Thats y i have posted this question.
 

If we assume hardware is okay. Then please Test this hardware for only transmission of data to PC hyper terminal not on simulator. Same for reception condition. After that combine both please do not use interrupt for transmission but add some 100 ms delay after each transmission character. If it work then reduce this delay by trial/error
 

I checked as you said, but still the data seems garbage on hyperterminal...

Is there any Bug in my code?

please see it...

If its possible, can u run my code into your hardware?
 

I care for baudrate. I am selecting 9600 baudrate in my terminal program. But it shows me garbage character.
 

Thank you for interest to help me,


My total project file is attached with here,
 

Attachments

  • USART_interrupt_32.rar
    10.5 KB · Views: 94

turn echo off and reply back with incremented value
 

Hello fouwad,

I have tried all tricks by incrementing value, decrementing, inverting and all experiments. But still there is problem.
 

If u send "A" from uc then what is observation on Hyperterminal. How u confirm ur Frequency of controller. Use Timer & genrate some Time ISR from this we can confirm ur Frequency is Okay
 
  • Like
Reactions: Briez

    Briez

    Points: 2
    Helpful Answer Positive Rating
Cross check your fuse settings

From where i can check my fuse bits setting in avr studio 4?

- - - Updated - - -

If u send "A" from uc then what is observation on Hyperterminal. How u confirm ur Frequency of controller. Use Timer & genrate some Time ISR from this we can confirm ur Frequency is Okay

when i send 'A' from terminal, uc responds with character shown in fig. RS-232.JPG
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top