Not able to get serial data from ads1293 sensor using nRF52833

Hi, I am working on project to obtain ecg data via bluetooth. But before that I was trying to see whether I could obtain ECG signals serially through nrf52833. And I tried a lot but in segger RTT viewer, I am only seeing zeros. My sensor is ads1293 breakout board from protocentral and this one works fine because I have already used it with my Arduino UNO and I was able to get the signal. But when connected with nRF52833, I am not getting any values. What should I do?

#include <stdio.h>
#include "nrf_drv_spi.h"
#include "nrf_gpio.h"
#include "nrf_delay.h"
#include "app_error.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

/* -------- PIN DEFINITIONS -------- */

#define DRDY_PIN 11
#define CS_PIN 12
#define SCK_PIN 13
#define MISO_PIN 14
#define MOSI_PIN 15

/* -------- ADS1293 REGISTERS -------- */

#define REG_CONFIG 0x00
#define REG_SAMPLING 0x21
#define REG_CH_CNFG 0x2F
#define REG_CMDET_EN 0x12
#define REG_RLD_SEL 0x20
#define REG_RLD_CNFG 0x1F

#define REG_CH1_H 0x37
#define REG_CH2_H 0x3A
#define REG_CH3_H 0x3D

#define REG_REVID 0x40
#define REG_STATUS 0x41

static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(0);

/* -------- SPI BYTE TRANSFER -------- */

uint8_t spi_transfer(uint8_t data)
{
uint8_t rx;

APP_ERROR_CHECK(
nrf_drv_spi_transfer(&spi, &data, 1, &rx, 1)
);

return rx;
}

/* -------- REGISTER WRITE -------- */

void writeRegister(uint8_t addr, uint8_t value)
{
nrf_gpio_pin_clear(CS_PIN);

spi_transfer(addr);
spi_transfer(value);

nrf_gpio_pin_set(CS_PIN);
}

/* -------- REGISTER READ -------- */

uint8_t readRegister(uint8_t addr)
{
uint8_t val;

nrf_gpio_pin_clear(CS_PIN);

spi_transfer(addr | 0x80);
val = spi_transfer(0x00);

nrf_gpio_pin_set(CS_PIN);

return val;
}

/* -------- READ 24 BIT ECG -------- */

int32_t read24(uint8_t reg)
{
int32_t value = 0;

nrf_gpio_pin_clear(CS_PIN);

spi_transfer(reg | 0x80);

value |= ((int32_t)spi_transfer(0x00) << 16);
value |= ((int32_t)spi_transfer(0x00) << 8);
value |= ((int32_t)spi_transfer(0x00));

nrf_gpio_pin_set(CS_PIN);

/* sign extension */

if (value & 0x800000)
value |= 0xFF000000;

return value;
}

/* -------- MAIN -------- */

int main(void)
{
/* LOG INIT */

NRF_LOG_INIT(NULL);
NRF_LOG_DEFAULT_BACKENDS_INIT();

NRF_LOG_INFO("ADS1293 ECG Start");

/* GPIO SETUP */

nrf_gpio_cfg_output(CS_PIN);
nrf_gpio_cfg_input(DRDY_PIN, NRF_GPIO_PIN_NOPULL);

nrf_gpio_pin_set(CS_PIN);

/* SPI CONFIG */

nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;

spi_config.sck_pin = SCK_PIN;
spi_config.mosi_pin = MOSI_PIN;
spi_config.miso_pin = MISO_PIN;

spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
spi_config.mode = NRF_DRV_SPI_MODE_1;
spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;

APP_ERROR_CHECK(
nrf_drv_spi_init(&spi, &spi_config, NULL, NULL)
);

nrf_delay_ms(100);

/* -------- SPI TEST -------- */

uint8_t id = readRegister(REG_REVID);
NRF_LOG_INFO("REV ID: %d", id);

uint8_t status = readRegister(REG_STATUS);
NRF_LOG_INFO("STATUS: %d", status);

NRF_LOG_FLUSH();

/* -------- CONFIGURE ADS1293 -------- */

writeRegister(REG_SAMPLING, 0x05); // sampling rate
writeRegister(REG_CH_CNFG, 0x30); // channel routing

writeRegister(REG_CMDET_EN, 0x01); // common mode detect
writeRegister(REG_RLD_SEL, 0x07); // RLD electrode select
writeRegister(REG_RLD_CNFG, 0x04); // enable RLD

writeRegister(REG_CONFIG, 0x01); // start conversion

nrf_delay_ms(10);

NRF_LOG_INFO("ECG Streaming Started");

/* -------- ECG LOOP -------- */

while (true)
{
if (nrf_gpio_pin_read(DRDY_PIN) == 0)
{
int32_t ch1 = read24(REG_CH1_H);
int32_t ch2 = read24(REG_CH2_H);
int32_t ch3 = read24(REG_CH3_H);

NRF_LOG_INFO("%d,%d,%d", ch1, ch2, ch3);
NRF_LOG_FLUSH();
}
}
}
This is the code that I am using. 

Parents Reply Children
No Data
Related