SPI to control ADS1299 (TI) using MATLAB and Bluetooth

Hello,
I have a relatively extensive problem. I want to use Matlab to send commands to an Arduino via Bluetooth. Depending on the command, the Arduino should then use the SPI interface to control the IC ADS1299 (data sheets in the appendix). This is used to record EEG signals.
More precisely, I use the ADS1299EEG-FE, but only the part on the chip with the electronics is built in. (See photo)
The communication between MATLAB and the Arduino is rudimentary and sufficient.
At the moment I'm hanging on to the configuration of the SPI, which turns out to be more complicated than I thought.
Currently I have the following code:

#include <SoftwareSerial.h>
#include <SPI.h>

int TxD;
int RxD;
int data;
int d1 = 0;
const byte WAKEUP  = 00000010;
const byte STANDBY = 00000100;
const byte RESET   = 00000110;
const byte START   = 00001000;
const byte STOP    = 00001010;
const byte RDATAC  = 00010000;
const byte SDATAC  = 00010001;
const byte RDATA   = 00010010;
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);
 // nextMillis = millis();
  bluetooth.begin(9600);
  SPI.begin();
  SPI.beginTransaction(SPISettings(1600000, MSBFIRST, SPI_MODE0));
}

void loop()
{
  if (bluetooth.available() > 0)
  {
    data = bluetooth.read();
    Serial.print(data);
    Serial.print("\n");

    if (data == 'H')
    {
      digitalWrite(SS, LOW);                      /* Turn SlaveSelect Level to low*/
      delay(5);                                   /* all delays for stability*/
    }
    else if (data == 'U')
    {
      SPI.transfer(WAKEUP);                       /* Turn off standby mod */
      Serial.println("Turn off standby Sent.");
      delay(5);
    }

    else if (data == 'X')
    {
      SPI.transfer(RDATAC);                     /* Start reading data constantly */
      Serial.println("Start Reading Sent.");
      delay(1);
    }

    else if (data == 'Z')
    {
      SPI.transfer(SDATAC);                     /*Stop reading data */
      Serial.println("Stop Reading Sent.");
      delay(5);
      digitalWrite(SS, HIGH);                   /* Turn SlaveSelect Level to high*/
    }
  }
}

With the help of an oscilloscope I can see that the SlaveSelect changes the level with the appropriate command. However, I cannot see that any commands sent over the MOSI cable are still received over the MISO cable. Also the CLK does not start.
I think I have a basic thinking error in my code. It would be great if someone of you could have a look at my code and take a look at the datasheets. Maybe you have some ideas?
In the future I would send the read out data via Bluetooth to my computer, but that is irrelevant for now.
Thanks for everything,
Wing354

Texas_Instruments-ADS1299IPAG-datasheet.pdf (1.8 MB)

const byte RDATAC  = 00010000;
const byte SDATAC  = 00010001;
const byte RDATA   = 00010010;

Those values will NOT fit in a byte. 0b00010010 would, but 10010 will not.

Thanks for your answer! I changed the bytes! :slight_smile:
A basic question, if I program the SPI as specified in the code, wouldn't the MOSI level have to be "low" all the time? At least as long as a command is sent? Unfortunately, I can't see that a command is being sent over the cable. It cannot be due to the Bluetooth connection, because I can change the level of the SlaveSelect at any time.
A second question. Do I have to start the SCLK myself? I don't see any running even with "SPI.beginTransaction", although the SlaveSelect is set to "low".
Many thanks in advance and excuse my probably stupid questions.
Wing354

1 Like