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.

problem in sending data to pc from microcontroller

Status
Not open for further replies.

suraksha s

Newbie level 5
Joined
Jan 18, 2013
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,330
sir actually this is my serial program to send a letter 'a' on hyper terminal but when i try to load the program to controller ATMEGA 32 and try to display on hyperterminal i am unable to get the data. please help me out as soon as possible

#include <avr/io.h>

int main(void)
{

UCSRC |= (1<<UMSEL); // select asynchronous mode
UCSRC |= (1<<USBS);
UBRRH = 51>>8; // higher 8 bits of 51
UBRRL = 51; // lower 8 bits of 51
UCSRB |= (1<<RXEN)|(1<<TXEN); // enable transmitter and receiver both
UCSRC |= (1<<UCSZ0)|(1<<UCSZ1); // number of data bits is 8

unsigned int send='a';

while((UCSRA & (1<<UDRE))==0) {};

UDR=send;



}
 


sir eventhough if i give a loop and changed it as unsigned char i am not getting output

- - - Updated - - -

this is the changes i have made

#include <avr/io.h>

int main(void)
{

UCSRC |= (1<<UMSEL); // select asynchronous mode
UCSRC |= (1<<USBS);
UBRRH = 51>>8; // higher 8 bits of 51
UBRRL = 51; // lower 8 bits of 51
UCSRB |= (1<<RXEN)|(1<<TXEN); // enable transmitter and receiver both
UCSRC |= (1<<UCSZ0)|(1<<UCSZ1); // number of data bits is 8

unsigned char send='a';
while(1)
{
while((UCSRA & (1<<UDRE))==0) {};

UDR=send;
}



}
 

Where is your interrupt routine for serial communication and you have to include interrupt.h file. I think you are using Atmel Studio. Use the code in the pdf I posted.

Did you try this code?

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
#include < avr / io .h >
#include < avr / interrupt .h >
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE ((( F_CPU / ( USART_BAUDRATE * 16 UL ))) - 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
}

 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top