engallam
Junior Member level 1
Hi I'm try to connect atmega32a with atmega8a using UART protocal but...
(in simulation)
- when I send byte from atmega32 to atmega8, the connection work good
- when I send byte from atmega8 to atmega32,the connection not work
(in real)
- the data recived by atmega8 (transmuted by atmega32) , be wrong data (Ex: when i send (1) from atmega32 the data received by atmega8 be (24)
- when I send byte from atmega8 to atmega32, the connection not work
what the problem ??!
code of atmega32a
code of atmega8a
(in simulation)
- when I send byte from atmega32 to atmega8, the connection work good
- when I send byte from atmega8 to atmega32,the connection not work
(in real)
- the data recived by atmega8 (transmuted by atmega32) , be wrong data (Ex: when i send (1) from atmega32 the data received by atmega8 be (24)
- when I send byte from atmega8 to atmega32, the connection not work
what the problem ??!
code of atmega32a
Code:
#define F_CPU 16000000
#include <avr\io.h>
#include <avr\pgmspace.h>
#include <avr\interrupt.h>
#include <util\delay.h>
#include <math.h>
#define ButtonPort PORTA // Buttons port
#define ButtonDir DDRA // Buttons Direction
#define ButtonPin PINA // Buttons port
#define Down 0 // Down Button
#define Up 1 // Up Button
#define Right 2 // Right Button
#define Left 3 // Left Button
#define Run 4 // Run Button
#define Back 5 // Back Button
int main(void)
{
DDRB=0xff;
PORTB=0x00;
ButtonDir=0x00;
ButtonPort=0xff;
uint16_t baud = 2400;
uint16_t UBRR_Value = lrint (( F_CPU / (16 * baud) ) - 1);
UBRRL = (uint8_t) UBRR_Value;
UBRRH = (uint8_t) (UBRR_Value >> 8);
UCSRB = (1<<RXEN) | (1<<TXEN);
UCSRC |= (1 << UPM1); //Sets parity to EVEN
UCSRC |= (3 << UCSZ0); //8-bit data length
while (1)
{
if (bit_is_clear(ButtonPin,Up))
{
_delay_ms(500);
while( ! (UCSRA & (1<<UDRE) ) );
UDR = 1;
}
if (bit_is_clear(ButtonPin,Down))
{
_delay_ms(500);
while( ! (UCSRA & (1<<UDRE) ) );
UDR = 2;
}
if (bit_is_clear(ButtonPin,Right))
{
_delay_ms(500);
while( ! (UCSRA & (1<<UDRE) ) );
UDR = 4;
}
if (bit_is_clear(ButtonPin,Left))
{
_delay_ms(500);
while( ! (UCSRA & (1<<UDRE) ) );
UDR = 8;
}
if (bit_is_clear(ButtonPin,Run))
{
_delay_ms(500);
while( ! (UCSRA & (1<<UDRE) ) );
UDR = 16;
}
while (! (UCSRA & (1 << RXC)) );
PORTB= UDR;
_delay_ms(500);
}
}
code of atmega8a
Code:
#define F_CPU 16000000
#include <avr\io.h>
#include <avr\pgmspace.h>
#include <avr\interrupt.h>
#include <util\delay.h>
#include <math.h>
int main(void)
{
DDRB=0xff;
PORTB=0x00;
uint16_t baud = 2400;
char data=5;
uint16_t UBRR_Value = lrint (( F_CPU / (16 * baud) ) - 1);
UBRRL = (uint8_t) UBRR_Value;
UBRRH = (uint8_t) (UBRR_Value >> 8);
UCSRB = (1<<RXEN) | (1<<TXEN);
UCSRC |= (1 << UPM1); //Sets parity to EVEN
UCSRC |= (3 << UCSZ0); //8-bit data length
while (1)
{
while (! (UCSRA & (1 << RXC)) );
PORTB= UDR;
_delay_ms(500);
while( ! (UCSRA & (1<<UDRE) ) );
UDR = data;
_delay_ms(500);
}
}