Hello all,
I am working on a load cell project for obtaining measurement data from 4 cells at ~1000Hz. I have so far been successful using an Arduino Uno but I am trying to move over to an ESP32 so that I can attempt to pass the data onto my computer using the in-built bluetooth. These are the parts I am using:
- microcontroller: Arduino Uno/ ESP32 (Firebeetle breakout board)
- ADC: TI ADS1262 (Protocentral breakout board)
- Level shifter: TXS0108E https://www.ti.com/lit/ds/symlink/txs0108e.pdf?ts=1637410567327&ref_url=https%253A%252F%252Fwww.google.com%252F
- Power Source: USB connection/ Uno for 5V
I have built the circuit on breadboard and double checked it was functional with the Arduino Uno. I have then replaced the Uno with the ESP32 and using a level shifter for the SPI channels since the ADC is supplied 5V. For the moment I am using the Uno to provide the 5V source, with hopes of a better power source when I can get the ESP32 up and running.
The issue that I am encountering (or so I think), is that I cannot get the SPI communication working because the ADC's DRDY line (for when data is ready) never goes low and I get an infinite loop in the wait() function. I am very new to the ESP32 and I could not find many examples on SPI so I am fairly sure I am implementing it wrong.
I have seen the ESP32 SPI class and tried to follow their example however when I instantiate the class like this:
SPIClass SPI1(VSPI);
The ESP32 reboots periodically without anything happening.
Below I have attached the initialise function within the .cpp file for the ADS1262 implementation that starts the SPI communication. I unfortunately do not have access to an oscilloscope to know what the SPI is outputting, but the exact same implementation worked on the Arduino Uno (minus the level shifter circuitry for 3.3V <---> 5V).
P.S. I can post more of the code including the .ino file if that will help my chances
Working .cpp file for Arduino UNO:
#include <Arduino.h>
#include <ads1262.h>
#include <SPI.h>
#include <digitalWriteFast.h>
int32_t ads1262::ads1262_Read_Data()
{
int32_t regData;
//digitalWrite(ADS1262_CS_PIN, LOW);
regData |= SPI.transfer(CONFIG_SPI_MASTER_DUMMY);
regData <<= 8;
regData |= SPI.transfer(CONFIG_SPI_MASTER_DUMMY);
regData <<= 8;
regData |= SPI.transfer(CONFIG_SPI_MASTER_DUMMY);
regData <<= 8;
regData |= SPI.transfer(CONFIG_SPI_MASTER_DUMMY);
digitalWriteFast(ADS1262_CS_PIN, HIGH);
return regData;
}
void ads1262::ads1262_Init()
{
// start the SPI library:
SPI.begin();
SPI.setBitOrder(MSBFIRST);
//CPOL = 0, CPHA = 1
SPI.setDataMode(SPI_MODE1);
SPI.setClockDivider(SPI_CLOCK_DIV2);
ads1262_Reset();
delay(100);
ads1262_Hard_Stop();
delay(350);
ads1262_Enable_Start();
// SPI.endTransaction();
}
Not -working code on ESP32:
#include <Arduino.h>
#include <ads1262.h>
#include <SPI.h>
// #include <digitalWriteFast.h>
// SPIClass SPI1(VSPI);
void ads1262::ads1262_Init()
{
// start the SPI library:
SPI.begin(18, 19, 23, D3);
SPI.setBitOrder(MSBFIRST);
//CPOL = 0, CPHA = 1
SPI.setDataMode(SPI_MODE1);
// SPI.setClockDivider(SPI_CLOCK_DIV2);
SPI.setFrequency(8000000); // 8MHz upper limit of ADS1262
// int SPISpeed = 8000000;
// SPI.beginTransaction( SPISettings( SPISpeed, MSBFIRST, SPI_MODE1) );
ads1262_Reset();
delay(100);
ads1262_Hard_Stop();
delay(350);
ads1262_Enable_Start();
// SPI.endTransaction();
}