Sign in

username:

password:



Not a member?

Search avrclub



Search tips

Subscribe to avrclub



avrclub by Keywords

AT90S2313 | AT90S8515 | ATMega | ATmega128 | ECL | FETS | IAR | Keyboard | LCD | STK50 | TMOS | UART

Ads

Discussion Groups

Discussion Groups | AVRclub | [AVR club] AVR serial interface

Atmel AVR Microcontroller discussion group.

[AVR club] AVR serial interface - doctor_adnan2003 - Jul 21 10:26:21 2008

I have to interface ATMEGA32 to a serial port
i have written the code
but when i simulate it in proteus, unrecognized charaters are displayed
i.e 0x43 should print C but it prints some other character
i am using proteus v7
any suggestions
regards
Adnan
------------------------------------



(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )


Re: [AVR club] AVR serial interface - Zack Widup - Jul 21 10:30:53 2008


Hi Adnan,

You might have to send out your code. It's difficult to say what's going
on without seeing it.

Zack

On Mon, 21 Jul 2008, doctor_adnan2003 wrote:

> I have to interface ATMEGA32 to a serial port
> i have written the code
> but when i simulate it in proteus, unrecognized charaters are displayed
> i.e 0x43 should print C but it prints some other character
> i am using proteus v7
> any suggestions
> regards
> Adnan

------------------------------------



(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: [AVR club] AVR serial interface - Felipe Uderman - Jul 21 17:05:04 2008

Also verify that the two peers are using the same baud rate.
On 7/21/08, Zack Widup wrote:

>
> Hi Adnan,
>
> You might have to send out your code. It's difficult to say what's going
> on without seeing it.
>
> Zack
>
> On Mon, 21 Jul 2008, doctor_adnan2003 wrote:
>
> > I have to interface ATMEGA32 to a serial port
> > i have written the code
> > but when i simulate it in proteus, unrecognized charaters are displayed
> > i.e 0x43 should print C but it prints some other character
> > i am using proteus v7
> > any suggestions
> > regards
> > Adnan
> >
> >

--
Uderman
http://wiki.temadigital.com.br
[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: [AVR club] AVR serial interface :THE CODE - doctor_adnan2003 - Jul 23 9:17:24 2008

below i am giving the code the settings in proteus are clock 4MHz
baud rate 9600

#include
#include
#include

#define F 4000000 /* oscillator-frequency
in Hz */
#define UART_BAUD_RATE 9600
#define UART_BAUD_CALC(UART_BAUD_RATE,FC) (F/(UART_BAUD_RATE*16l)-1)

void usart_putc(unsigned char c) {
// wait until UDR ready
while(!(UCSRA & (1 << UDRE)));
UDR = c; // send character
}

void uart_puts (char *s) {
// loop until *s != NULL
while (*s) {
usart_putc(*s);
s++;
}
}

void init(void) {
// set baud rate
UBRRH = (uint8_t)(UART_BAUD_CALC(UART_BAUD_RATE,F)>>8);
UBRRL = (uint8_t)UART_BAUD_CALC(UART_BAUD_RATE,F);

// Enable receiver and transmitter; enable RX interrupt
//UCSRB = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE);
UCSRB = (1< //asynchronous 8N1
UCSRC = (1 << URSEL) | (3 << UCSZ0);
}

int main(void) {
init(); // init USART
//sei(); // enable interrupts

// send initial character
while ( !(UCSRA & (1 << UDRE)) );
UDR = 0x43; // "C"
while (!(UCSRA & (1 << UDRE)));
UDR = 0x69;
return 0;
}

------------------------------------



(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

[AVR club] Re: AVR serial interface - doctor_adnan2003 - Jul 23 9:18:12 2008

#include
#include
#include

#define F 4000000 /* oscillator-frequency
in Hz */
#define UART_BAUD_RATE 9600
#define UART_BAUD_CALC(UART_BAUD_RATE,FC) (F/(UART_BAUD_RATE*16l)-1)

void usart_putc(unsigned char c) {
// wait until UDR ready
while(!(UCSRA & (1 << UDRE)));
UDR = c; // send character
}

void uart_puts (char *s) {
// loop until *s != NULL
while (*s) {
usart_putc(*s);
s++;
}
}

void init(void) {
// set baud rate
UBRRH = (uint8_t)(UART_BAUD_CALC(UART_BAUD_RATE,F)>>8);
UBRRL = (uint8_t)UART_BAUD_CALC(UART_BAUD_RATE,F);

// Enable receiver and transmitter; enable RX interrupt
//UCSRB = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE);
UCSRB = (1< //asynchronous 8N1
UCSRC = (1 << URSEL) | (3 << UCSZ0);
}

int main(void) {
init(); // init USART
//sei(); // enable interrupts

// send initial character
while ( !(UCSRA & (1 << UDRE)) );
UDR = 0x43; // "C"
while (!(UCSRA & (1 << UDRE)));
UDR = 0x69;
return 0;
}

------------------------------------



(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: [AVR club] Re: AVR serial interface - ahmed elnmr - Jul 23 16:01:43 2008

I think that you should use oscillator-frequency 11.0592MHZ

--- On Wed, 23/7/08, doctor_adnan2003 wrote:

From: doctor_adnan2003
Subject: [AVR club] Re: AVR serial interface
To: a...@yahoogroups.com
Date: Wednesday, 23 July, 2008, 2:31 PM

#include
#include
#include

#define F 4000000 /* oscillator-frequenc y
in Hz */
#define UART_BAUD_RATE 9600
#define UART_BAUD_CALC( UART_BAUD_ RATE,FC) (F/(UART_BAUD_ RATE*16l) -1)

void usart_putc(unsigned char c) {
// wait until UDR ready
while(!(UCSRA & (1 << UDRE)));
UDR = c; // send character
}

void uart_puts (char *s) {
// loop until *s != NULL
while (*s) {
usart_putc(* s);
s++;
}
}

void init(void) {
// set baud rate
UBRRH = (uint8_t)(UART_ BAUD_CALC( UART_BAUD_ RATE,F)>> 8);
UBRRL = (uint8_t)UART_ BAUD_CALC( UART_BAUD_ RATE,F);

// Enable receiver and transmitter; enable RX interrupt
//UCSRB = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE);
UCSRB = (1< //asynchronous 8N1
UCSRC = (1 << URSEL) | (3 << UCSZ0);
}

int main(void) {
init(); // init USART
//sei(); // enable interrupts

// send initial character
while ( !(UCSRA & (1 << UDRE)) );
UDR = 0x43; // "C"
while (!(UCSRA & (1 << UDRE)));
UDR = 0x69;
return 0;
}

__________________________________________________________
Not happy with your email address?.
Get the one you really want - millions of new email addresses available now at Yahoo! http://uk.docs.yahoo.com/ymail/new.html

[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )