ruchirvn
Newbie level 4
Hi,
I want to send and receive 16 bit data using USART. How it can be done ? If I transmit by splitting 16bit data into two bytes will I receive in the same order ? If No then plz suggest me an alternate solution
My Code is given below
/*
* AVRGCC3.c
*
* Created: 1/14/2012 12:11:38 AM
* Author: Ruchir
*/
//#define __AVR_ATmega16__ 1
//#define OSCSPEED 8000000 /* in Hz */
#define DATA_REGISTER_EMPTY (1<<UDRE)
#include "avr/io.h"
void Initialize(void)
{
PORTB = 0xFF;
PORTC = 0xFF;
PORTD = 0x00;
DDRB = 0x00;
DDRC = 0x00;
DDRD = 0x00;
}
void UARTInit(void)
{
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;
}
void UARTTransmit(unsigned char data)
{
/* Wait for empty transmit buffer */
while ( ( UCSRA & DATA_REGISTER_EMPTY )==0 );
/* Put data into buffer, sends the data */
UDR = data;
}
int main()
{
unsigned char ch,ch1;
Initialize();
UARTInit();
while (1)
{
ch = PINB;
ch1 = PINC;
//ch = (PINB | 0xC0);
//ch1 = (PINC & 0x3F);
//ch = UARTReceive();
UARTTransmit(ch);
UARTTransmit(ch1);
}
}
Thanks
I want to send and receive 16 bit data using USART. How it can be done ? If I transmit by splitting 16bit data into two bytes will I receive in the same order ? If No then plz suggest me an alternate solution
My Code is given below
/*
* AVRGCC3.c
*
* Created: 1/14/2012 12:11:38 AM
* Author: Ruchir
*/
//#define __AVR_ATmega16__ 1
//#define OSCSPEED 8000000 /* in Hz */
#define DATA_REGISTER_EMPTY (1<<UDRE)
#include "avr/io.h"
void Initialize(void)
{
PORTB = 0xFF;
PORTC = 0xFF;
PORTD = 0x00;
DDRB = 0x00;
DDRC = 0x00;
DDRD = 0x00;
}
void UARTInit(void)
{
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;
}
void UARTTransmit(unsigned char data)
{
/* Wait for empty transmit buffer */
while ( ( UCSRA & DATA_REGISTER_EMPTY )==0 );
/* Put data into buffer, sends the data */
UDR = data;
}
int main()
{
unsigned char ch,ch1;
Initialize();
UARTInit();
while (1)
{
ch = PINB;
ch1 = PINC;
//ch = (PINB | 0xC0);
//ch1 = (PINC & 0x3F);
//ch = UARTReceive();
UARTTransmit(ch);
UARTTransmit(ch1);
}
}
Thanks