cancel
Showing results for 
Search instead for 
Did you mean: 

ADS1293 sensor interface with STM32nucleo-u083rc board

Raman_2004
Associate

I have to interface the nucleo-u083rc with ads1293 to get ecg data. I have provided the code from stm32cubeide and also the ioc picture. I have connected the D4 pin(MCU) as DRDYB pin and SPI1 and I use channel 1 from the sensor. Please help me with the code to get things right.

STM32 Cubeide:

/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/

#include "main.h"

 

/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

#include<string.h>

#include<stdio.h>

 

/* USER CODE END Includes */

 

/* Private typedef -----------------------------------------------------------*/

/* USER CODE BEGIN PTD */

// ADS1293 Register Addresses

#define REG_CH_CNFG 0x2F

#define REG_DRDYB_SRC 0x27

#define REG_MASK_DRDYB 0x20

#define REG_DATA_LOOP 0x50

/* USER CODE END PTD */

 

/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */

uint32_t data;

int32_t ecg;

int32_t ecgData;

/* USER CODE END PD */

 

/* Private macro -------------------------------------------------------------*/

/* USER CODE BEGIN PM */

 

/* USER CODE END PM */

 

/* Private variables ---------------------------------------------------------*/

 

SPI_HandleTypeDef hspi1;

 

UART_HandleTypeDef huart2;

 

/* USER CODE BEGIN PV */

 

/* USER CODE END PV */

 

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_SPI1_Init(void);

static void MX_USART2_UART_Init(void);

/* USER CODE BEGIN PFP */

 

/* USER CODE END PFP */

 

/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */

void ADS1293_WriteReg(uint8_t address, uint8_t data) {

uint8_t dataToSend[1];

uint8_t addrToSend[1];

dataToSend[0]=(address & 0x7F);

addrToSend[0]=data;

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, RESET);

HAL_SPI_Transmit(&hspi1, dataToSend, 1, HAL_MAX_DELAY);

HAL_SPI_Transmit(&hspi1, addrToSend, 1, HAL_MAX_DELAY);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, SET);

}

 

 

 

 

uint8_t ads1293readdata(uint8_t rdAddress)

{

uint8_t rdData;

uint8_t dataToSend[1];

uint8_t zero[1]={0};

dataToSend[0]= (rdAddress | 0x80);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, RESET);

HAL_SPI_Transmit(&hspi1, dataToSend, 1, HAL_MAX_DELAY);

rdData=HAL_SPI_Transmit(&hspi1, zero, 1, HAL_MAX_DELAY);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, SET);

 

return rdData;

}

 

uint32_t getECGdata(uint8_t channel){

 

uint8_t rawData[3];

if(channel < 1 || channel > 3){

return -1; //return error, -1

}else {

channel -= 1;

}

 

rawData[0] = ads1293readdata(0x37 + (channel * 3));

rawData[1] = ads1293readdata(0x38 + (channel * 3));

rawData[2] = ads1293readdata(0x39 + (channel * 3));

 

uint32_t tempData = (uint32_t)rawData[0] << 16;

tempData = (uint32_t)rawData[1]<< 8;

tempData |= rawData[2];

tempData = tempData << 8;

 

 

ecgData = (int32_t) (tempData);

return ecgData ;

}

 

void ADS1293_Init() {

// Write initial configuration

ADS1293_WriteReg(0x01, 0x11); // Set input multiplexer

HAL_Delay(1);

ADS1293_WriteReg(0x02, 0x19); // Set input multiplexer for channel 2

HAL_Delay(1);

ADS1293_WriteReg(0x0A, 0x07); // Enable CMDET for IN1, IN2, IN3

HAL_Delay(1);

ADS1293_WriteReg(0x0C, 0x04); // Connect RLD amplifier to IN4

HAL_Delay(1);

ADS1293_WriteReg(0x12, 0x04); // Use external crystal

HAL_Delay(1);

ADS1293_WriteReg(0x14, 0x24); // Shut down unused channel 3 path

HAL_Delay(1);

ADS1293_WriteReg(0x21, 0x02); // Set R2 decimation rate to 5

HAL_Delay(1);

ADS1293_WriteReg(0x22, 0x02); // Set R3 decimation rate to 6 for channel 1

HAL_Delay(1);

ADS1293_WriteReg(0x23, 0x02); // Set R3 decimation rate to 6 for channel 2

HAL_Delay(1);

ADS1293_WriteReg(0x27, 0x08); // Set DRDYB source to channel 1 ECG

HAL_Delay(1);

ADS1293_WriteReg(0x2F, 0x30); // Enable ECG mode for loop read-back

HAL_Delay(1);

ADS1293_WriteReg(0x00, 0x01); // Start data conversion

HAL_Delay(1);

}

 

/* USER CODE END 0 */

 

 

int main(void)

{

 

/* USER CODE BEGIN 1 */

 

/* USER CODE END 1 */

 

/* MCU Configuration--------------------------------------------------------*/

 

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

 

/* USER CODE BEGIN Init */

 

/* USER CODE END Init */

 

/* Configure the system clock */

SystemClock_Config();

 

/* USER CODE BEGIN SysInit */

 

/* USER CODE END SysInit */

 

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_SPI1_Init();

MX_USART2_UART_Init();

/* USER CODE BEGIN 2 */

 

ADS1293_Init();

HAL_Delay(10);

 

/* USER CODE END 2 */

 

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

 

if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_5) == GPIO_PIN_RESET)

{

 

ecg = getECGdata(1);

char uart_buffer[12];

//sprintf(uart_buffer, "%08lX\r\n", ecg); // Convert data to hexadecimal string

sprintf(uart_buffer, "%ld\r\n", ecg);

HAL_UART_Transmit(&huart2, (uint8_t*)uart_buffer, strlen(uart_buffer), HAL_MAX_DELAY);

HAL_Delay(1000);

}

 

}

/* USER CODE END 3 */

}

 

ioc image:

Raman_2004_0-1735382695638.png

 

2 REPLIES 2
Pavel A.
Evangelist III

Which things are not right?

Here you can find enthusiastic help for your issue.

 

 

I couldn't read the data. I don't know how to figure it out as I am new to this sensor interfacing.