I send data to UART, revert it and send it back. Problem is somehow delay - related.
This value between received chars was selected in experiment, this way eveything works great:
_delay_us(150);
When i use code below, eveything works as intended, problems start, when i uncomment _delay_ms(100);
When I send up to 3 char everything is stil ok, but if i send:
1234 i receive 421
123456 - 721
12345678 - 821
Can sameone explain what is happening ?
#define F_CPU 1843200UL// Clock Speed #define BAUD 115200UL #define MYUBRR ((F_CPU/(8*BAUD))-1) #include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> #include <stdlib.h> #include "avr/iom64a.h" int main(void) { UBRR0H = (unsigned char)(MYUBRR>>8); UBRR0L = (unsigned char)MYUBRR; UCSR0A = (1 << U2X0); /* Enable receiver and transmitter */ UCSR0B = (1 << RXEN0) | (1 << TXEN0); //| (1 << RXCIE0); /* Set frame format: 8data, 1stop bit, no parity */ UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); //0x06; //sei(); int8_t aa = 0x31; while (1) { //_delay_ms(100); if(( UCSR0A & 0x80))//RX { char table[10]; int8_t iii = 0; for(; UCSR0A & 0x80;) { table[iii] = UDR0; _delay_us(150); if(UCSR0A & 0x80) iii++; } PORTA ^= 0x08; for(int8_t kkk = iii; kkk >= 0; kkk--) { while ( !( UCSR0A & 0x20) ); UDR0 = table[kkk]; } } } }