• 大小: 2KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-21
  • 语言: 其他
  • 标签: ADS1292R  心电  ECG  

资源简介

使用STM32F405的SPI通信接口对ADS1292R进行寄存器配置的参考代码源文件。

资源截图

代码片段和文件信息


#include “ads1292r.h“
#include “stm32f4xx_hal_spi.h“
#include 
#include “string.h“
#include “spi.h“

// active LOW
void ads_Reset(uint8_t reset)
{
if(reset)
HAL_GPIO_WritePin(ADS_RESET_GPIO_Port ADS_RESET_Pin GPIO_PIN_SET);
else
HAL_GPIO_WritePin(ADS_RESET_GPIO_Port ADS_RESET_Pin GPIO_PIN_RESET);
}

// active LOW
void ads_CS(uint8_t cs)
{
if(cs)
HAL_GPIO_WritePin(ADS_CS_GPIO_Port ADS_CS_Pin GPIO_PIN_SET);
else
HAL_GPIO_WritePin(ADS_CS_GPIO_Port ADS_CS_Pin GPIO_PIN_RESET);
}

// active HIGH
void ads_Start(uint8_t start)
{
if(start)
HAL_GPIO_WritePin(ADS_START_GPIO_Port ADS_START_Pin GPIO_PIN_SET);
else
HAL_GPIO_WritePin(ADS_START_GPIO_Port ADS_START_Pin GPIO_PIN_RESET);
}

uint8_t  ads_Read_ID(void)
{
  uint8_t send_data[3] read_data[3];
send_data[0] = ADS1292R_CMD_RREG_1(ADS1292R_REG_ID);
send_data[1] = ADS1292R_CMD_RREG_2(1);
send_data[2] = 0x00;

while(HAL_OK!= HAL_SPI_TransmitReceive(&hspi1send_dataread_data31000));

return read_data[2];

}

void ads_Init(void)
{
uint8_t send_data[20] read_data[20];

ads_Reset(1); // 复位引脚置一,正常工作

osDelay(1000);

// ads_CS(0);

osDelay(100);

//指令:停止连续读数据模式
send_data[0]=ADS1292R_CMD_SDATAC;  
while(HAL_OK!= HAL_SPI_TransmitReceive(&hspi1send_dataread_data11000));

osDelay(10);

//写配置寄存器2=0xa0,内部参考电压为2.42V
send_data[0] = ADS1292R_CMD_WREG_1(ADS1292R_REG_CONFIG2);
send_data[1] = ADS1292R_CMD_WREG_2(1);
send_data[2] = 0xa0;

while(HAL_OK!= HAL_SPI_TransmitReceive(&hspi1send_dataread_data31000));

osDelay(10);

//写配置寄存器1=0x01,连续转换模式,采样率为250
send_data[0] = ADS1292R_CMD_WREG_1(ADS1292R_REG_CONFIG1);
send_data[1] = ADS1292R_CMD_WREG_2(1);
send_data[2] = 0x01;

while(HAL_OK!= HAL_SPI_TransmitReceive(&hspi1send_dataread_data31000));

osDelay(10);

//写导联脱落检测寄存器=0xF0,正负极分别为70%和30%,该功能实际未使用
send_data[0] = ADS1292R_CMD_WREG_1(ADS1292R_REG_LOFF);
send_data[1] = ADS1292R_CMD_WREG_2(1);
send_data[2] = 0xF0;

while(HAL_OK!= HAL_SPI_TransmitReceive(&hspi1send_dataread_data31000));

osDelay(10);

//写通道1设置寄存器=0x30,设置增益为3,正常节点输入
send_data[0] = ADS1292R_CMD_WREG_1(ADS1292R_REG_CH1SET);
send_data[1] = ADS1292R_CMD_WREG_2(1);
send_data[2] = 0x30;

while(HAL_OK!= HAL_SPI_TransmitReceive(&hspi1send_dataread_data31000));

osDelay(10);

//写右腿驱动寄存器=0xEF,PGA的斩波频率为4分频,使能右腿驱动,关闭右腿驱动的脱落检测,通道2的右腿驱动负极和正极分别连接到通道2输入的负极和正极,通道1的右腿驱动负极和正极分别连接到通道1的负极和正极
send_data[0] = ADS1292R_CMD_WREG_1(ADS1292R_REG_RLD_SENS);
send_data[1] = ADS1292R_CMD_WREG_2(1);
send_data[2] = 0xEF;

while(HAL_OK!= HAL_SPI_TransmitReceive(&hspi1send_dataread_data31000));

osDelay(10);

//写脱落检测寄存器=0x0F,关闭通道1和2的电流方向检测,使能通道1和2的正负极脱落检测
//其实只使用了通道1,而且脱落检测实际上没有使用
send_data[0] = ADS1292R_CMD_WREG_1(ADS1292R_REG_LOFF_SENS);
send_data[1] = ADS1292R_CMD_WREG_2(1);
send_data[2] = 0x0F;

while(HAL_OK!= HAL_SPI_TransmitReceive(&hspi1sen

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-01-15 03:15  ADS1292R配置源文件\
     文件        4288  2019-01-15 03:14  ADS1292R配置源文件\ads1292r.c
     文件        1267  2019-01-15 01:54  ADS1292R配置源文件\ads1292r.h

评论

共有 条评论