[SOLVED]Arduino Uno, Gameduino2 and ADS1298 (SPI issue)
Sept 8, 2014 7:38:40 GMT -8
hojjat likes this
Post by borjavr on Sept 8, 2014 7:38:40 GMT -8
Hi everybody!
I´m using this three devices, communicating through SPI: Arduino Uno, Gameduino2 and ADS1298 (analog to digital converter)
The idea is to build an electrocardiograph. ADS registers values from electrodes, converts, sends to Arduino and Arduino sends to Gameduino2 to plot data, but I have some problems.
Here is my code (some things not necesary deleted to make it more readable).
#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:
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!
I´m using this three devices, communicating through SPI: Arduino Uno, Gameduino2 and ADS1298 (analog to digital converter)
The idea is to build an electrocardiograph. ADS registers values from electrodes, converts, sends to Arduino and Arduino sends to Gameduino2 to plot data, but I have some problems.
Here is my code (some things not necesary deleted to make it more readable).
#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:
- I change SPI_MODE "on the fly" because it´s mandatory, devices' need.
- As you can see every part of the code related to ADS is wraped around CS_ADS_pin setting, and idem for Gameduino2
- The ADS part works fine (checked with Matlab)
- 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!