Witam,
Mam taki problem. Odbieram znaki w przerwaniu i nie wiem dlaczego jeśli wysyłam jakiś znak to pojawia się on w buforze odbiorczym a tego nie chce. Próbowałem funkcji uart_flush i nic nie pomaga.
Proszę o pomoc.
Mam taki problem. Odbieram znaki w przerwaniu i nie wiem dlaczego jeśli wysyłam jakiś znak to pojawia się on w buforze odbiorczym a tego nie chce. Próbowałem funkcji uart_flush i nic nie pomaga.
Proszę o pomoc.
#include <avr/io.h>
#include "uart.h"
// Funkcje
void uart_init ( unsigned int ubrr)
{
/*Set baud rate */
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char)ubrr;
/*Enable receiver and transmitter */
UCSR0B = (1<<RXEN0)|(1<<TXEN0)|(1<<RXC0);
/* Set frame format: 8data, 2stop bit */
UCSR0C = (1<<USBS0)|(3<<UCSZ00);
}
void uart_putc ( unsigned char data )
{
/* Wait for empty transmit buffer */
//UCSR0B &= ~(1<<RXEN0);
while ( !( UCSR0A & (1<<UDRE0)) );
/* Put data into buffer, sends the data */
UDR0 = data;
//UCSR0B |= 1<<RXEN0;
}
void uart_flush( void )
{
unsigned char dummy;
while ( UCSR0A & (1<<RXC0) ) dummy = UDR0;
}
void main( void )
{
if(...)
uart_putc('*');
}
SIGNAL (USART_RX_vect)
{
c = UDR0;
if ( (c != 0x0d) && (c != ' ') )
buff[m++] = c;
else
{
buff[m] = '\0';
flaga = 1;
}
}