Steps for RS232 communication using Atmega16 and VB.net application
1. Set Baud Rate
#define F_CPU 8000000L
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
2. Register Setting
UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UCSRB |= (1 << RXCIE); // Enable the USART Recieve Complete interrupt (USART_RXC)
3. Interrupt Routine
// this will echo back the same char
ISR(USART_RXC_vect) {
char R;
R = UDR;
UDR = R;
}
4. sei();
5. main()
and infinite loop
No comments:
Post a Comment