Hello,
I'm trying to program an SPI to control the chip ADS1299 from TI. For this I have made some basic configurations.
Arduino Uno (Pin 13) SCLK - ADS1299 SCLK
Arduino Uno (Pin 12) MISO - ADS1299 DIN
Arduino Uno (Pin 11) MOSI - ADS1299 DOUT
Arudino Uno (Pin 10) SS - ADS1299 CS
Ground connected, and all TP of the ADS1299EEG FE board checked (correct voltages), additionally I use a digital oscilloscope to view the signals.
The commands, which the Arduino should send as master to the ADS1299 as slave, are received by the Arduino via a Bluetooth antenna and MATLAB from my PC. So don't be surprised about the Bluetooth lines in the code.
I wrote the following code:
#include <SoftwareSerial.h>
#include <SPI.h>
int TxD;
int RxD;
int data;
const int WAKEUP = 0x02;
const byte STANDBY = 0b00000100;
const byte RESET = 0b00000110;
const byte START = 0b00001000;
const byte STOP = 0b00001010;
const byte RDATAC = 0b00010000;
const byte SDATAC = 0b00010001;
const byte RDATA = 0b00010010;
const byte TEST = 0b1000000010000000;
const byte TEST1 = 0b00000000;
const byte READREGISTER = 0b00100000;
const byte READREGISTER2 = 0b00000001;
int x=0;
int i = 1;
unsigned long nextMillis = 0;
SoftwareSerial bluetooth(TxD, RxD);
/* SPI pin numbers:
SCK 13 // Serial Clock.
MISO 12 // Master In Slave Out.
MOSI 11 // Master Out Slave In.
SS 10 // Slave Select*/
void setup() {
Serial.begin(9600);
digitalWrite(SS, HIGH);
pinMode(SS, OUTPUT);
;
nextMillis = millis();
bluetooth.begin(9600);
SPI.begin();
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE1));
}
void wakeup()
{
SPI.transfer(WAKEUP);
}
void standby()
{
SPI.transfer(STANDBY);
}
void readregister()
{
SPI.transfer(READREGISTER);
delay(0.001);
SPI.transfer(READREGISTER);
delay(0.001);
byte rx = SPI.transfer(TEST1);
delay(0.001);
byte rt = SPI.transfer(TEST1);
}
void start()
{
SPI.transfer(START);
}
void stop()
{
SPI.transfer(STOP);
}
void rdatac()
{
SPI.transfer(RDATAC);
delay(1000);
x = 1;
byte receivedVal = 0b00000000; ;
while (x == 1)
{
delay(100);
while (i <= 9)
{
digitalWrite(SS, LOW);
digitalWrite(MOSI, LOW);
SPI.transfer(TEST, 3);
digitalWrite(MOSI, LOW);
delay(0.000000001);
digitalWrite(SS, HIGH);
i = i + 1;
}
i = 1;
if (bluetooth.available() > 0)
{
data = bluetooth.read();
if (data == 'B')
{
x = 0;
digitalWrite(SS, LOW);
}
}
}
}
void sdatac()
{
SPI.transfer(SDATAC);
}
void rdata()
{
SPI.transfer(RDATA);
delay(100);
i = 1;
while (i <= 9)
{
digitalWrite(SS, LOW);
SPI.transfer(&TEST, 3);
delay(0.0000001);
digitalWrite(SS, HIGH);
i = i + 1;
}
digitalWrite(SS, LOW);
}
void loop()
{
if (bluetooth.available() > 0)
{
data = bluetooth.read();
Serial.print(data);
Serial.print("\n");
if (data == 'H')
{
digitalWrite(SS, LOW);
}
else if (data == 'U')
{
wakeup();
delay(10);
}
else if (data == 'B')
{
standby();
delay(10);
}
else if (data == 'T')
{
readregister();
delay(1000);
}
else if (data == 'S')
{
start();
delay(10);
}
else if (data == 'P')
{
stop();
delay(10);
}
else if (data == 'R')
{
rdatac();
}
else if (data == 'r')
{
rdata();
delay(10);
}
else if (data == 'Z')
{
sdatac();
delay(100);
//digitalWrite(SS, HIGH); /* Turn SlaveSelect Level to high*/
}
}
}
Enclosed I'll add a flowchart, which should be observed when starting up the ADS1299 and a logic protocol, which I get when I query the register for the ID. Unfortunately the chip does not answer me as desired and I would like to ask you if you have an idea what could be the reason in this case or what I am doing wrong?
DRDY pulsates and I send the SDATAC command first.
Moderator edit: images inlined