I am trying to enable simple Uart communication with my computer.
I am using atmega32 microcontroller and inbuilt Terminal in Atmel Studio 7
This is my code:
#ifndef F_CPU #define F_CPU 1000000ul #endif #include <avr/io.h> #include <util/delay.h> #include <stdlib.h> #include <stdio.h> void init() { UCSRB |= (1<<TXEN) | (1<<RXEN); UCSRC |= (1<<URSEL) | (1<<UCSZ0) | (1<<UCSZ1); UBRRL = 6 UBRRH = (6 >> 8); } void USART_Transmit(unsigned char data) { while(!(UCSRA & (1<<UDRE))); UDR = data; } unsigned char USART_Receive(void) { while((UCSRA & (1<<RXC)) == 0); return UDR; } int main(void) { unsigned char c; init(); while (1) { c = USART_Receive(); USART_Transmit(c); } }
The problem is when I try to send the character I'm getting back garbage value like this (¥§¶ß··öŸ)
Can you help me please!