Hello,
I'm testing UART communication, have problem with function usage.
#define F_CPU 1843200UL// Clock Speed #define BAUD 115200UL #define MYUBRR ((F_CPU/(16*BAUD))-1) #include <avr/io.h> #include <util/delay.h> #include <stdlib.h> void USART0_Transmit(unsigned char wejscie) { while ( !( UCSR0A & 0x20) ); UDR0 = wejscie; return; } void USART0_Init(unsigned int); void uart_puts(char * ); int main(void) { /* Set baud rate */ UBRR0H = (unsigned char)(MYUBRR>>8); UBRR0L = (unsigned char)MYUBRR; /* Enable receiver and transmitter */ UCSR0B = 0x18; /* Set frame format: 8data, 1stop bit, no parity */ UCSR0C = 0x06; // USART0_Init ( MYUBRR ); while (1) { while ( !( UCSR0A & 0x20) ); UDR0 = 0x31; while ( !( UCSR0A & 0x20) ); UDR0 = 0x32; USART0_Transmit(0x33); _delay_ms(1000); } }
In console i receive 123, and no delay. If I comment:
//USART0_Transmit(0x33);
i receive 12 and 1 second delay. I noticed similar problems yesterday with external interrupt - they didnt returned to last point.