Here is a better explanation of my problem (simplified code):
#include <SPI.h>
#include <EEPROM.h>
#include <GD2.h>
//Pin configuration
const int CS_GD_pin = 8;
const int CS_ADS_pin = A5;
const int MOSI_pin = 11;
const int MISO_pin = 12;
const int SCK_pin = 13;
void setup() {
//Pin settings
pinMode(CS_GD_pin, OUTPUT);
digitalWrite(CS_GD_pin, HIGH);
pinMode(CS_ADS_pin, OUTPUT);
digitalWrite(CS_ADS_pin, HIGH);
pinMode(MOSI_pin, OUTPUT);
pinMode(MISO_pin, INPUT);
pinMode(SCK_pin, OUTPUT);
pinMode(ADSReset_pin,OUTPUT);
GD.begin();
}
void loop() {
plot();
ADS_ready();
attachInterrupt(ADSInterrupt, read_subfunction, FALLING);
delay(100);
detachInterrupt(ADSInterrupt);
digitalWrite(CS_ADS_pin, HIGH);
}
void plot() {
digitalWrite(CS_GD_pin, LOW);
//Here plotting code which is basically (for the moment) an order to plot the matrix, with GD.Begin(POINTS) and GD.Vertex2ii...
digitalWrite(CS_GD_pin, HIGH);
}
void ADS_ready() {
digitalWrite(CS_ADS_pin, LOW);
//Initialize SPI for ADS
SPI.begin();
SPI.setDataMode(SPI_MODE1);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV8);
//Here some ADS settings
}
void read_subfunction(){
//Here reading code, when ADS says new data are ready the interrupt is activated and Arduino enters this ISR and stores data into a matrix
}
Some important points:
1.I change SPI_MODE "on the fly" because it´s mandatory, devices' need.
2.As you can see every part of the code related to ADS is wraped around CS_ADS_pin setting, and idem for Gameduino2
3.The ADS part works fine (checked with Matlab)
4.Gameduino part does not work. If I put a counter inside plot() I can see the program enters, but it´s like it only swaps for the first time. For example, if inside plot() I forget about the matrix and build a little program to display a counter on the screen with one second delay (1,2,3...) it only plots 1.
I think there is a problem with the Gameduino2 SlaveSelect pin (8, CS_GD_pin in my program). I tried with GD.__end(), GD.resume() and so, I admit I don´t understand very well Gameduino libraries because I´m not an expert at all, so any help is gladly appreciate!