Hello,
I'm currently doing arduino mega 2560 communication project with atmega128 via UART. i get some problems then i check the communication system with proteus simulator (put a virtual monitor on each UART lane) so i can find out which lane the problem stay in. here the complete details:
purpose :
the atmega128 need to send 24 data of adc (from 24 analog sensors) value through UART1 of arduino 2560 after receiving command from arduino. i did it well so far as the virtual monitor on each UART lane (UART1 of mega2560 which is used to send command and receive the data) show complete data stream except for UART0 of arduino mega that i use to display the data into serial monitor (i use tera term) or kind of GUI app.
problem :
i did some works to display all of the data but the serial monitor only show about 11 or sometimes 12 data instead of 24.
i just use simple code to read and write the data :
int thisByte, thisByteReply;
byte thisByteIndex[6] = "";
byte thisByteIndexReply[24] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int flag_device1, flag_device2, flag_device3, flag_device4;
int index = 0;
int indexReply = 0;
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
}
void loop()
{
//evaluate the command from PC and forward to atmega128
while (Serial.available())
{
thisByte = Serial.read();
thisByteIndex[index] = thisByte;
if (index < 6)
{
Serial.println(thisByte, HEX); // sending echo to GUI
index++;
if (index > 5)
{
index = 0;
thisByte = 0;
}
}
detFlag();
execute();
}
//read value from atmega and display to GUI/tera term
while (Serial1.available())
{
thisByteReply = Serial1.read();
thisByteIndexReply[indexReply] = thisByteReply;
//Serial.println(thisByteReply);
Serial.write(thisByteIndexReply, 24);
//Serial.println("");
}
}
i just start to learn arduino code into further and need help now
i appreciate any useful help
thanks