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] Sending Data from ATmega32 to PC SERIAL Communication CVAVR

Status
Not open for further replies.

drtvskuthsav

Member level 2
Joined
Apr 7, 2010
Messages
46
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,630
Hi I need small help in sending data from Atmega32 to PC via Serial Port(atleast printf). I use CodeVision AVR compiler and Proteus to simulate. I can receive data from the PC to Micro but the other way is not happening. I am getting some garbage values in the terminal. Am attaching the circuit and the code is as given


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
Chip type               : ATmega32
Program type            : Application
AVR Core Clock frequency: 7.372800 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 512
*****************************************************/
 
#include <mega32.h>
#include <stdio.h>
#include <delay.h>
void main(void)
{
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0xb6;/*odd parity, 8bit*/
UBRRH=0x00;
UBRRL=0x2f;/*9600*/
 
 
 
while (1)
      {
      printf("kuthsav");
      delay_ms(1000);// Place your code here
 
      }
}


View attachment usartone_0001.jpg


Thanks to all in advance
 
Last edited by a moderator:

i think its with the parity , i think you should try without the parity check and it might work . I have not yet worked on code vision avr but it you want i can give you the code for avrstudio . and another mistake i think with the program is that you should put a value of 0x33 in ubrrl , try it ...
 

i think its with the parity , i think you should try without the parity check and it might work . I have not yet worked on code vision avr but it you want i can give you the code for avrstudio .
Can you please post the code...And also explain me how to check the parity.. I tried UCSRC but it did not help me much. I receive garbage value on my terminal.
and another mistake i think with the program is that you should put a value of 0x33 in ubrrl
I've used 7.372800 MHz as clock frequency...Its mentioned in the specification..
 

Have you set the port and debug window to 9600 too?
 

Yes..Am simulating it on Proteus..I've given Odd parity,9600 and one stop bit in respective fields of Virtual Terminal shown in circuit. I also used Tera Virtual Terminal and I've given the same Parameters. Though it is showing some garbage values it is different from the one shown in Virtual terminal of Proteus.
 

Code:
#include <util/delay.h>

void init_serial(unsigned char rate)
{
	UCSRB = (1<<TXEN)|(1<<RXEN)|(1<<RXCIE); // transmission enable with interrupt
	UCSRC = (1<<UCSZ0)|(1<<UCSZ1)|(1<<URSEL);
	UBRRL = rate;
}	

void uart_print(unsigned char ch)           //what ever you want to send serially to the tx pin.
{
	while(! (UCSRA & (1<<UDRE)));
	UDR = ch;
//	_delay_ms(100);
}

void uart_puts (char *s)
{
    while (*s)	//While *s is not NULL
    {
        uart_print(*s);
        s++;
    }
}



void uart_print_delay(unsigned char ch)//, unsigned char pause)           //what ever you want to send serially to the tx pin.
{
	while(! (UCSRA & (1<<UDRE)));
	UDR = ch;
	_delay_ms(100);
}

void uart_puts_delay(char *s)//,unsigned char pause)
{
    while (*s)	//While *s is not NULL
    {
        uart_print_delay(*s);//, pause);
        s++;
    }
}

void start()
{
 unsigned char str[23] = "\n\r this is how it starts \n";
 unsigned char i = 0;
 for (i = 0 ; i <= 23 ; i++)
 {
 uart_print(str[i]);
 }
}

these are the normal initializations that are required , you just need to calculate the value in hex to be put into init_serial() , i think this should work ...

---------- Post added at 18:09 ---------- Previous post was at 18:09 ----------

sorry for so late reply ...
 
Last edited by a moderator:

I had the same problem last year...
one choice can be reducing the baudrate.
try 1200
 

Thank you guys. Thank you very much. The problem was solved. It was just a problem with setting fuse bits. Anyways now I learnt that part. ;)
 

Can you please help me with the receiving codes. I want to drive motor via serial communication using ATMEGA 32
 

Can you please help me with the receiving codes. I want to drive motor via serial communication using ATMEGA 32
Hi Rcario,
You just want to start and stop motor or want to vary its speed as well.??
 

hello drtvskuthsav, I just want to start and stop actually.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top