Answer the question
In order to leave comments, you need to log in
How to transfer data from Arduino Mega to Atmega8A via UART?
The task is to transfer data from the Arduino Mega2560 to the Atmega8A AVR microcontroller .
Found the reverse problem and it works.
Initially, I wrote with my hands according to the Atmega datasheet and materials one , two , three .
I tried to use ready-made libraries for Arduino and for Atmega .
Arduino code:
unsigned char n;
void setup() {
Serial1.begin(9600);
pinMode(19,INPUT);//RXD pin is set for INPUT
pinMode(18,OUTPUT);
}
void loop() {
// if (Serial1.available()) {
//for(n=100; n<= 255;n++){
//Serial1.print(n, BIN);
Serial1.print(0b00001000, BIN);
delay(1000);
//}
// }
}
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
unsigned char m;
m = 7;
portIni();
LCDIni();
setPos(0,0);
//unsigned char n; // Переменная общего счётчика
char buffer [64];
DDRD |= (1 << PIND0);//PORTD pin0 as INPUT
DDRC=0xFF;//PORTC as OUTPUT
int UBRR_Value = 6; // 9600 baud rate
UBRRH = (unsigned char) (UBRR_Value >> 8);
UBRRL = (unsigned char) UBRR_Value;
UCSRB = (1 << RXEN) | (1 << TXEN);
//UCSRC = (1 << USBS) | (3 << UCSZ0);
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
//UCSRB = (1<<RXEN)|(1<<TXEN)|(1<<RXCIE)|(TXCIE);
/* Set frame format: 8data, 1stop bit */
//UCSRC = (1<<URSEL)|(3<<UCSZ0);
unsigned char receiveData;
//sprintf(buffer, "Wait...", m);
//LCDString(buffer);
//_delay_ms(1000);
while (1)
{
while (! (UCSRA & (1 << RXC)) );
receiveData = UDR;
if (receiveData >= 0x01){
LCDClear();
sprintf(buffer, "%3d", receiveData);
LCDString(buffer);
_delay_ms(2);
} else {
LCDClear();
sprintf(buffer, "Wait...", m);
LCDString(buffer);
_delay_ms(1000);
}
}
}
Answer the question
In order to leave comments, you need to log in
I see 2 errors.
DDRD &= ~(1 << PIND0); //PORTD pin0 as INPUT
UBRRH = 0;
UBRRL = 103;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question