Hello Guys, I'm having problems with USART to read one and more caracters by register.
My USART init function:
void Usart_interrupt_init(void) // this function is correct
{
//cli();
UBRR0H = (BAUD_PRESCALER >> 8);
UBRR0L = BAUD_PRESCALER;
UCSR0A &= ~(1 << U2X0);
UCSR0B = ((1<<RXEN0)|(1<<TXEN0)|(1 << RXCIE0));
UCSR0C = ((0<<USBS0)|(1 << UCSZ01)|(1<<UCSZ00));
sei();
}
This is my code to read a single caracter. But when I try to read a caracter in main function sending by serial monitor, it only read when I type a caracter twice.
char Receive_Data(void) {
while ( !( UCSR0A & (1 << RXC0)) ) {
}
return UDR0;
}
This is my USART Interruption, but it seens the code never enter it.
#define RX_BUFFER_SIZE 128
volatile char rxBuffer[RX_BUFFER_SIZE];
volatile uint8_t rxReadPos = 0;
volatile uint8_t rxWritePos = 0;
// my code continues here
ISR(USART0_RXC)
{
rxBuffer[rxWritePos] = UDR0;
rxWritePos++;
if(rxWritePos >= RX_BUFFER_SIZE)
{
rxWritePos = 0;
}
}
// end of my code
When I try to print rxBuffer on main, nothing happens, like if I never entered in the interruption.
Obs: This function is working, but I need to programm by register and can't use it.
if(Serial.available() > 0)
{
teste = Serial.read();
printf("%c ",teste);
}