This is my first post. So, I am not entirely sure if this is the correct forum.
I am trying to write a parallel communication protocol between 2 Arduino Mega. I am planning to use PORTA for data and a few other pins for control.
So here is my test code -
Master transmits -
byte i = 0;
int intpin = 44;
int rcv_ready = 45;
void setup(){
DDRA = B11111111;
pinMode(intpin, OUTPUT);
pinMode(rcv_ready, INPUT);
}
void loop(){
digitalWrite(intpin, HIGH);
while(rcv_ready == LOW){}
PINA = i++;
digitalWrite(intpin, LOW);
delay(299);
}
Slave receives
int rcv_ready = 45;
void setup()
{
DDRA = B00000000; //input
Serial.begin(19200);
attachInterrupt(5, blink, RISING);
pinMode(rcv_ready, OUTPUT);
digitalWrite(rcv_ready, LOW);
}
void loop()
{
}
void blink()
{
digitalWrite(rcv_ready, HIGH);
Serial.println(PINA);
digitalWrite(rcv_ready, LOW);
}
The transfer is mostly working, except for some errors.
84
1
87
0
88
1
91
0
92
1
95
0
96
1
99
0
100
1
103
0
104
1
107
0
108
1
111
0
112
1
115
0
116
1
119
0
120
Error # -
- I have random 0s and 1s in alternate lines.
- It is printing 2 numbers and then skipping the next two numbers.
I am have no clue what the problem might be.
I have connected Pin 22-37 and 45 of master to Pin 22-37 and 45 of the slave. Pin 18 of Slave is connected Master's Pin 44. I plan to use PORTC (Pin 30-37) in the future but currently i am not sending any signals.
I will appreciate any help.
Thanks in advance.