This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS1292R: SPI not working with ESP32

Part Number: ADS1292R
Other Parts Discussed in Thread: ADS1292

Hi,

When I tried to use the function ""ECG_SENSOR_ADS1292R.getAds1292EcgAndRespirationSamples()"", the ESP32 is going on a reboot, it seems it is entering into mathematical invalid condition. can you help here.

Regards,

Nitin

3632.ECG.txt
#include "protocentralAds1292r.h"
#include "SPI.h"


#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"  //creating the service UUID
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"  //creating the characteristics UUID

#define ESP32_V_SPI_CS_PIN 5
#define ADS1292R_PWRDN_PIN 27
#define ADS1292R_START_PIN 15
#define ADS292R_DATAREADY_PIN 22

char Reg_read_data;
bool data_available;

#define LED_BUILTIN 2 //pin with LED to turn on when BT connected

ads1292OutputValues* ADS1292RegValues; 
ads1292r ECG_SENSOR_ADS1292R;


/*------------------------Setup or main function.---------------------------*/
void setup() {

  pinMode(ESP32_V_SPI_CS_PIN,OUTPUT);
  pinMode(ADS1292R_PWRDN_PIN,OUTPUT);
  pinMode(ADS1292R_START_PIN,OUTPUT);
  pinMode(ADS292R_DATAREADY_PIN,INPUT);
   
  digitalWrite(ESP32_V_SPI_CS_PIN,LOW);
  digitalWrite(ADS1292R_PWRDN_PIN,LOW);
  digitalWrite(ADS1292R_START_PIN,HIGH);
  SPI.begin();
  
  Serial.begin(9600); // define the baud rate of ESP32

  Serial.println("Starting BLE work!");



/*-------------------------------------------------------------------------------------------*/
/*-------------Setting up the Sensor------------------------*/

  ECG_SENSOR_ADS1292R.ads1292Reset(ADS1292R_PWRDN_PIN);
  delay(1000);
  ECG_SENSOR_ADS1292R.ads1292Init(ESP32_V_SPI_CS_PIN,ADS1292R_PWRDN_PIN,ADS1292R_START_PIN);
  delay(1000);
  Serial.println("ECG sensor initialised.");
  data_available = ECG_SENSOR_ADS1292R.getAds1292EcgAndRespirationSamples(ADS292R_DATAREADY_PIN,ESP32_V_SPI_CS_PIN,ADS1292RegValues);
  data_available=true;
 if (data_available==true){
  Serial.print("The data is ready");
 }
  ECG_SENSOR_ADS1292R.ads1292Reset(ADS1292R_PWRDN_PIN);


  
//For Debug purpose only.
//Reading the Chip ID
//  pinMode(ESP32_V_SPI_CS_PIN,OUTPUT);
//  pinMode(ADS1292R_PWRDN_PIN,OUTPUT);
//  pinMode(ADS1292R_START_PIN,OUTPUT);
  
//  digitalWrite(ESP32_V_SPI_CS_PIN,LOW);
//  digitalWrite(ADS1292R_PWRDN_PIN,LOW);


//  ECG_SENSOR_ADS1292R.ads1292RegRead(ESP32_V_SPI_CS_PIN,ADS1292R_PWRDN_PIN,ADS1292_REG_ID,Reg_read_data);
//  Serial.println("CHIP ID is:");
//  Serial.println(Reg_read_data,HEX);
}
Error.txt
ECG sensor initialised.
Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400d0e24  PS      : 0x00060730  A0      : 0x800d0ceb  A1      : 0x3ffb1f60  
A2      : 0x3ffbfeac  A3      : 0xff800000  A4      : 0x3ffbfecc  A5      : 0x00000000  
A6      : 0x00000009  A7      : 0x00000000  A8      : 0x80000000  A9      : 0x3ffbfebc  
A10     : 0x00000003  A11     : 0x00000001  A12     : 0x3ffbfeb0  A13     : 0x3ffbfeb8  
A14     : 0x3ffbfed0  A15     : 0x00000000  SAR     : 0x0000001b  EXCCAUSE: 0x0000001d  
EXCVADDR: 0x00000000  LBEG    : 0x400d0d94  LEND    : 0x400d0db9  LCOUNT  : 0x00000000  

ELF file SHA256: 0000000000000000

Backtrace: 0x400d0e24:0x3ffb1f60 0x400d0ce8:0x3ffb1f80 0x400d1fd2:0x3ffb1fb0 0x40086189:0x3ffb1fd0

Rebooting...
D⸮ ⸮	]q⸮⸮
⸮⸮⸮h⸮Starting BLE work!
data_output_AD1292r.txt
C0
0
0
80
0
0
80
0
0
 

  • Hi Yang,

    Thanks for your suggestions and prompt feedback.

    I tried both the options but nothing worked for me. However, I tried reading the chip id of the ADS1292r, but that was reading ZERO.

    The above is the function that was used reading the register, which I added into the library files.

    char ads1292r::ads1292RegRead(const int chipSelect,const int pwdnPin,const int startPin,unsigned char REG_ADDRESS,byte REG_DATA){

    /* //register address
    #define ADS1292_REG_ID 0x00
    #define ADS1292_REG_CONFIG1 0x01
    #define ADS1292_REG_CONFIG2 0x02
    #define ADS1292_REG_LOFF 0x03
    #define ADS1292_REG_CH1SET 0x04
    #define ADS1292_REG_CH2SET 0x05
    #define ADS1292_REG_RLDSENS 0x06
    #define ADS1292_REG_LOFFSENS 0x07
    #define ADS1292_REG_LOFFSTAT 0x08
    #define ADS1292_REG_RESP1 0x09
    #define ADS1292_REG_RESP2 0x0A */


    // start the SPI library:
    ads1292StopReadDataContinuous(chipSelect); // SDATAC command
    delay(300);

    // combining(Logic ORing) the register address with the read command opcode RREG(001r)=h'2 into one byte:
    byte regToRead = REG_ADDRESS | RREG;
    // take the chip select low to select the device:
    digitalWrite(chipSelect, LOW);
    delay(10);
    SPI.transfer(regToRead); //Send register location
    SPI.transfer(0x00); //number of register to read
    //delay(100);
    REG_DATA=SPI.transfer(CONFIG_SPI_SLAVE_DUMMY); //Send value to record into register

    // take the chip select high to de-select:
    digitalWrite(chipSelect, HIGH);

    }




    ECG_debug.txt
    // This is BLE based server client model.
    // This part of the code sends ECG signal from ADS1292R ECG sensor, to the mobile app via ESP32 using the BLE protcol.
    // This is server code as all the sensors correspond/act like servers which advertise to the client(mobile app) when they are ready to transfer the app.
    
    /*
     VSPI PIN OUT FOR ESP32
     CS       D5
     SCLK     D18
     MOSI     D23
     MISO     D19
    
     HSPI PIN OUT FOR ESP32
     CS       D15
     SCLK     D14
     MOSI     D13
     MISO     D12
    
     Here we have VSPI hardware.
    */
    
    //#include <BLEDevice.h>
    //#include <BLEUtils.h>
    //#include <BLEServer.h>
    //#include "BLE2904.h"
    #include "protocentralAds1292r.h"
    #include "SPI.h"
    
    
    
    // See the following for generating UUIDs:
    // https://www.uuidgenerator.net/
      
    
    #define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"  //creating the service UUID
    #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"  //creating the characteristics UUID
    
    #define ESP32_V_SPI_CS_PIN 5
    #define ADS1292R_PWRDN_PIN 27
    #define ADS1292R_START_PIN 15
    #define ADS292R_DATAREADY_PIN 22
    
    char Reg_read_data;
    bool data_available;
    
    #define LED_BUILTIN 2 //pin with LED to turn on when BT connected
    
    ads1292OutputValues* ADS1292RegValues; 
    ads1292r ECG_SENSOR_ADS1292R;
    /*-----------------Function to detect Lead off condition in ECG.----------------------*/
    
    /*------------------------------------------------------------------------------------*/
    
    /*------------------------Setup or main function.---------------------------*/
    void setup() {
    
      pinMode(ESP32_V_SPI_CS_PIN,OUTPUT);
      pinMode(ADS1292R_PWRDN_PIN,OUTPUT);
      pinMode(ADS1292R_START_PIN,OUTPUT);
      pinMode(ADS292R_DATAREADY_PIN,INPUT);
       
      digitalWrite(ESP32_V_SPI_CS_PIN,LOW);
      digitalWrite(ADS1292R_PWRDN_PIN,LOW);
      digitalWrite(ADS1292R_START_PIN,HIGH);
    
      SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE1));
      delay(100);
      SPI.begin();
      
      Serial.begin(9600); // define the baud rate of ESP32
    
    /*-------------Setting up the Sensor------------------------*/
    
    
    
      
    //For Debug purpose only.
    //Reading the Chip ID
      ECG_SENSOR_ADS1292R.ads1292RegRead(ESP32_V_SPI_CS_PIN,ADS1292R_PWRDN_PIN,ADS1292R_START_PIN,ADS1292_REG_ID,Reg_read_data);
      Serial.println("CHIP ID is:");
      Serial.println(Reg_read_data,HEX);
    
    
    
    }
    /*------------------------------------------------------------------------------------*/
    
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    
    }
    

    Please let me know how to resolve the issue.

    Regards,

    Nitin

  • Hi Nitin,

    I am not familiar with ESP32 uController and its dedicated SPI ports and/or engine.

    May I ask did you follow the correct power up sequence and reset mentioned in datasheet section 10 and 10.1 Power-Up Sequencing?

    Would you provide some oscilloscope screenshot regarding to above?

    If above is correct, please check the following -

    Do you set the SPI settings to CPOL = 0 and CPHA =1?

    Could you please probe on the CLK, /CS, SCLK, DIN, DOUT  when you try to read the 8.6.1.1 ID: ID Control Register (Factory-Programmed, Read-Only) (address = 00h)

    and see if the probed signals follow the timing diagram in Datasheet Page 11 and section 8.5.2.11 RREG: Read From Register and Figure 54.

    Thanks

  • Hi Yang,

    I have scoped the signals as you had asked, please find it below.

    the following is the start up sequence that I followed.

    digitalWrite(pwdnPin, HIGH);  // pull the reset/pwdn pin high for 1second.
    delay(1000);

    digitalWrite(pwdnPin, LOW); // then pull the reset pin low for 500ms to generate a pulse. 
    delay(500);
    digitalWrite(pwdnPin, HIGH); // then pull it high and wait for 9 seconds
    delay(9000);

    ads1292StopReadDataContinuous(chipSelect); // SDATAC command 
    delay(100);
    digitalWrite(chipSelect, LOW); // pull the CS pin low.
    delay(100);

    Please let me know if I have missed anything. Also I changed the settings for SPI mode to mode1 using arduino command for SPI.

    SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE1));
    delay(100);

    Please let me know  if there is any other register that I have to set in ADS1292r to make the change.

    Regards,

    Nitin

  • Hi,

    Would you please also send a scope image of your power up sequence?

    And, I am assuming the MOSI is DIN, please clarify if I am wrong.

    How many register are you trying to read?

    Did you follow data sheet page 42 and note that DIN is latched on the SCLK falling edge and DOUT are shifted out on the SCLK rising edge?

    Is your screenshot for Master requesting to read? i.e. send opcodes at DIN with SCLK first, then wait for DATA come out from DOUT with SCLK.

    The reason I am asking is because that from your screenshot - there are SCK's falling edges right on/align with the edges of DIN at beginning, if this is to request to read, it may not work properly.

    And, please refer to Table 15. and 8.5.2.11~12 about how to send opcodes for read or write.

    Thanks.

  • Hi Yang,

    Yes, you are correct MOSI is Din. Here Master is the ESP32 controller and ADS1292r is the slave.

    I am trying to read only one register at a time and that is why the data on MOSI is empty on 2nd set of SCLK, but on the other hand MISO or DOUT should have given me some out put on the third set of SCLK.

    I will shortly give you the  scope shots for power up sequence also.

    Regards,

    Nitin

  • Hi,

    Thanks.

    Please follow datasheet page 47, RREG

    (2) n nnnn = (number of registers to be read or written) – 1.

    For example, to read or write three registers, set n nnnn = 0 (0010).

    r rrrr = starting register address for read and write opcodes.

    so, in your case if reading only one register, the n nnnn should be 0 0000.

  • Hi Yang,

    That's exactly what I followed to do a SPI read but MISO/DOUT line doesn't read anything. Do you have a basic SPI read function that I can try out ?

    Regards,

    Nitin

  • Hi,

    Has this issue from earlier discussion been fixed?

    "

    Is your screenshot for Master requesting to read? i.e. send opcodes at DIN with SCLK first, then wait for DATA come out from DOUT with SCLK.

    The reason I am asking is because that from your screenshot - there are SCK's falling edges right on/align with the edges of DIN at beginning, if this is to request to read, it may not work properly.

    "

    Also, I briefly looked of your setup(), may I ask what do the following mean? And, where and why do you call the following?

    The reason I ask is that PWRDN_PIN is low assert/active for ADS1292R, so if you write it low, that means ADS1292R is asked to power down.

    Correct me if I misunderstood your code.

    "

    digitalWrite(ESP32_V_SPI_CS_PIN,LOW);
    digitalWrite(ADS1292R_PWRDN_PIN,LOW);
    digitalWrite(ADS1292R_START_PIN,HIGH);

    "

    The source code for EVM was written for MSP430, may not be appropriate for your MCU.

    However, you may check here to see if TI provides the source code for ADS1292REVM -

    https://www.ti.com/tool/ADS1192ECG-FE

    If not, it means TI does not provide source code for this EVM.

  • Hi,
    Since I did not hear back from you, I believe my suggestions answered your questions.
    I will close this post and if you have any pending questions, feel free to post them here or open a new thread.
    Thanks and have a great day!