Hello everyone,
I recently discovered my interest in electronics and, as a first project, I am trying to build a small ECG system. To get myself acquainted with the basics and in order to make sure I get the software side running properly, I wanted to connect a breakout board (ProtoCentral ADS1292R ECG/Respiration Breakout Kit - Protocentral Electronics). I set it up with an Arduino Nano first and it works well when running just code to read the ID from the register of the ADS1292R (I took some code from the protocentral repo to initialize the ADS1292R).
I am now trying to get it to run with a XIAO ESP32-C6, but I simply cannot establish the SPI communication. I took the code that ran on the Arduino and adjusted the SPI pins, but it doesnāt work. See below the code Iām trying to run right now. If anyone could help out or nudge me in the right direction, Iād be very grateful! Thanks a lot!
#include "protocentralAds1292r.h"
#include <SPI.h>
// Xiao ESP32-C6 config
const int ADS1292_DRDY_PIN = 0;
const int ADS1292_CS_PIN = 21;
const int ADS1292_START_PIN = 2;
const int ADS1292_PWDN_PIN = 17;
const int SPI_MISO = 20;
const int SPI_MOSI = 18;
const int SPI_SCK = 19;
ads1292r ADS1292R;
void sendSpiCommand(uint8_t cmd, uint8_t cs_pin) {
digitalWrite(cs_pin, LOW);
delayMicroseconds(10);
SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE1));
SPI.transfer(cmd);
SPI.endTransaction();
digitalWrite(cs_pin, HIGH);
delayMicroseconds(50);
}
uint8_t readRegister(uint8_t reg, uint8_t cs_pin) {
uint8_t value = 0;
digitalWrite(cs_pin, LOW);
delayMicroseconds(100);
SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE1));
SPI.transfer(0x20 | (reg & 0x1F));
SPI.transfer(0x00);
value = SPI.transfer(0x00);
SPI.endTransaction();
digitalWrite(cs_pin, HIGH);
delayMicroseconds(200);
return value;
}
void setup()
{
delay(2000);
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI, ADS1292_CS_PIN);
// SPI.setBitOrder(MSBFIRST);
// SPI.setDataMode(SPI_MODE1);
// SPI.setClockDivider(SPI_CLOCK_DIV16);
pinMode(ADS1292_DRDY_PIN, INPUT);
pinMode(ADS1292_CS_PIN, OUTPUT);
pinMode(ADS1292_START_PIN, OUTPUT);
pinMode(ADS1292_PWDN_PIN, OUTPUT);
Serial.begin(57600);
digitalWrite(ADS1292_CS_PIN, HIGH);
delay(50);
ADS1292R.ads1292Init(ADS1292_CS_PIN, ADS1292_PWDN_PIN, ADS1292_START_PIN);
delay(500);
sendSpiCommand(0x11, ADS1292_CS_PIN);
delay(10000);
Serial.println("Reading register...");
uint8_t id = readRegister(0x00, ADS1292_CS_PIN);
Serial.println(id, HEX);
}
void loop()
{
}