|
Quote:
Present a minimal program that builds, runs and displays the problem.
I am sending A, but don't receive A all the time.I am interfacing laptop with Receiver Tx , and seeing the output using Realterm. If I see the output in Uint format I get 208,11 and sometimes 65 which is transmitted character A.
My question is why I get 208 and 11?
Code for TX
Code:
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
void USARTInit(int ubrr_value);
void USARTWriteChar(char data);
#ifndef BAUDRATE
#define BAUDRATE 38400
#endif
#define BAUD_PRESCALE (((F_CPU/(BAUDRATE*16UL)))-1)
int main(void)
{
USARTInit(BAUD_PRESCALE);
while(1)
{
USARTWriteChar('A'); // send the data to USART Tx for transmission
}
}
void USARTInit(int ubrr_value)
{
//Set Baud rate
UBRR0 = ubrr_value;
//Enable The receiver and transmitter
UCSR0B=(1<<RXEN0)|(1<<TXEN0);
UCSR0C=(1<<USBS0)|(3<<UCSZ00);
}
void USARTWriteChar(char data)
{
while(!(UCSR0A & (1<<UDRE0)))
{
}
UDR0=data;
}
Code for Rx
Code:
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
void USARTInit(int ubrr_value);
char USARTReadChar();
void USARTWriteChar( char data);
#ifndef BAUDRATE
#define BAUDRATE 38400
#endif
#define BAUD_PRESCALE (((F_CPU/(BAUDRATE*16UL)))-1)
int main()
{
char data;
USARTInit(BAUD_PRESCALE);
while(1)
{
data=USARTReadChar();
USARTWriteChar(data);
}
}
void USARTInit(int ubrr_value)
{
//Set Baud rate
UBRR0 = ubrr_value;
UBRR1 = ubrr_value;
//Enable The receiver and transmitter
UCSR0B=(1<<RXEN0)|(1<<TXEN0);
UCSR0C=(1<<USBS0)|(3<<UCSZ00);
}
char USARTReadChar()
{
while(!(UCSR0A & (1<<RXC0)))
{
}
return UDR0;
}
void USARTWriteChar( char data)
{
while(!(UCSR0A & (1<<UDRE0)))
{
}
UDR0=data;
}
|