Hello All,
I have a not so typical task, I need to read 'data transfer' and EOI from GPIB (IEEE-488) using Arduino Mega. Basically, I'm triggering a function generator and I'm connected to the Arduino via GPIB.
What I want to do it's to read 8 bits (byte) from GPIB but only when EOI is 1, because in that case I have trigger active.
I have a code but it's not enough advanced. I am not sure is it my code not good enough to read when EOI is 1 (it's 1 just 300us), or my Arduino is to slow? Sometimes I am able to read EOI=1 but i get value of just fist byte and that's all.
const int DIO[] = {22, 23, 24, 25, 26, 27, 28, 29};
const int EOI_PIN = 38;
int bitValue[8]; // Declare bitValue as a global array
void setup() {
Serial.begin(9600);
for (int i = 0; i < 8; i++) {
pinMode(DIO[i], INPUT);
}
pinMode(EOI_PIN, INPUT);
int registerValue = PORTA;
for (int i = 0; i < 8; i++) {
int bitNumber = i;
int bitValue = bitRead(registerValue, bitNumber);
Serial.print("Value of bit ");
Serial.print(bitNumber);
Serial.print(" in PORTA: ");
Serial.println(bitValue, BIN);
}
}
void loop() {
int eoi = digitalRead(EOI_PIN);
delayMicroseconds(10);
if(eoi == 1) {
Serial.println(eoi, BIN);
// Use bitValue array in the loop code
/* for (int i = 0; i < 8; i++) {
if (bitValue[i] == 1) {
// Do something if the bit is HIGH
Serial.println(bitValue[i], BIN);
}
else {
// Do something else if the bit is LOW
Serial.println(bitValue[i], BIN);
}
}*/
/* int val[8];
for (int i = 0; i < 8; i++) {
val[i] = digitalRead(bitValue[i]);
Serial.print("DIO");
Serial.print(i+1);
Serial.print(":");
Serial.println(val[i], BIN);
}*/
// Serial.println(val[], BIN);
//delayMicroseconds(10);
}
else if (eoi == 0){
Serial.println(eoi, BIN);type or paste code here
Serial.println("It is no longer 1");
// delayMicroseconds(50);
}
}