Witam,
Chciałem sprawdzić czy będę dostawał odpowiedzi na wysłany komunikat. W tym calu wrzuciłem poniższy program na ATiny2313.
Niestety nie zależnie co wyślę dostaje cały czas taką samą odpowiedź i za bardzo nie wiem co jest nie tak
Czy byłby w stanie ktoś pomóc?

Chciałem sprawdzić czy będę dostawał odpowiedzi na wysłany komunikat. W tym calu wrzuciłem poniższy program na ATiny2313.
#include <avr/io.h>
#include <inttypes.h>
//This function is used to initialize the USART
//at a given UBRR value
void USARTInit(uint16_t ubrr_value)
{
//Set Baud rate
UBRRL = ubrr_value;
UBRRH = (ubrr_value>>8);
/*Set Frame Format
>> Asynchronous mode
>> No Parity
>> 1 StopBit
>> char size 8
*/
// UCSRC=(1<<URSEL)|(3<<UCSZ0);
//Enable The receiver and transmitter
UCSRB=(1<<RXEN)|(1<<TXEN);
}
//This function is used to read the available data
//from USART. This function will wait untill data is
//available.
char USARTReadChar()
{
//Wait untill a data is available
while(!(UCSRA & (1<<RXC)))
{
//Do nothing
}
//Now USART has got data from host
//and is available is buffer
return UDR;
}
//This fuction writes the given "data" to
//the USART which then transmit it via TX line
void USARTWriteChar(char data)
{
//Wait untill the transmitter is ready
while(!(UCSRA & (1<<UDRE)))
{
//Do nothing
}
//Now write the data to USART buffer
UDR=data;
}
void main()
{
//This DEMO program will demonstrate the use of simple
//function for using the USART for data communication
//Varriable Declaration
char data;
/*First Initialize the USART with baud rate = 19200bps
for Baud rate = 19200bps
UBRR value = 51
*/
USARTInit(51); //UBRR = 51
//Loop forever
while(1)
{
//Read data
data=USARTReadChar();
/* Now send the same data but but surround it in
square bracket. For example if user sent 'a' our
system will echo back '[a]'.
*/
USARTWriteChar('[');
USARTWriteChar(data);
USARTWriteChar(']');
}
}Niestety nie zależnie co wyślę dostaje cały czas taką samą odpowiedź i za bardzo nie wiem co jest nie tak
