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

See Also

DSPFPGAElectronics

Discussion Groups | AVRclub | [AVR club] Sending data By serial port

Atmel AVR Microcontroller discussion group.

[AVR club] Sending data By serial port - rahmatoolah abedini - Jun 12 9:17:32 2009

Dear Friends=20
Thanks a lot for your help.
I=E2=80=99m in first way for communication by serial port .I found my probl=
em after sending you my Email. I have a mistake in my hardware and have sol=
ved it. And I'm working with serial port now.But your sending data especial=
ly recommended program was very interesting for me.
Best regards Ali.
=20=20=20=20=20=20

[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 )


[AVR club] Re: Sending data By serial port - mahmoudxcom - Jun 14 19:51:08 2009

--- In a...@yahoogroups.com, rahmatoolah abedini wrote=
:
>
> Dear Friends=20
> Thanks a lot for your help.
> I=E2=80=99m in first way for communication by serial port .I found my pro=
blem after sending you my Email. I have a mistake in my hardware and have s=
olved it. And I'm working with serial port now.But your sending data especi=
ally recommended program was very interesting for me.
> Best regards Ali.
>=20
>=20
>=20=20=20=20=20=20=20
>=20
> [Non-text portions of this message have been removed]
>1- write this equation to calculate the baud rate=20
#define USART_BAUD 2400 // enter her the Baud as your desire=20
#define BAUD_UBRR (((F_CPU / (USART_BAUD * 16UL))) - 1)=20
2- write this function to TRANSMIT:=20=20

void USART_TRANSMIT(unsigned char data)
{
while((UCSRA & (1 << UDRE)) =3D=3D 0){} //wait for UDRE flag
UDR =3D data ; // load data to UDR=20
}

3- write this function to receive :=20

unsigned char USART_Receive( void )
{
/* Wait for data to be received */
while ( !(UCSRA & (1< /* Get and return received data from buffer */
return UDR;
}

4- finally this function to initiate USART :

void InitiateUSART()
{
UCSRB =3D (1 << RXEN) | (1 << TXEN);
UCSRC =3D (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
UBRRL =3D BAUD_UBRR;
UBRRH =3D (BAUD_UBRR >> 8);
}
note :
if you using internal 1MHZ clock you should not exceed the 2400 baud=20=20
=20

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



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