Browse Source

9.2.1 3-LeadECGApplication OK

3lead_uart_test_ok_version
zhaohe 1 year ago
parent
commit
fb7614708f
  1. 244
      1.c
  2. 2
      app/src/basic/ads1293/ads1293.c
  3. 447
      app/src/main.c

244
1.c

@ -0,0 +1,244 @@
#if 0
#define ADS1293_SPI_SCK_PIN (32 + 9)
#define ADS1293_SPI_MOSI_PIN 15
#define ADS1293_SPI_MISO_PIN 20
#define ADS1293_SPI_CS0_PIN 3
#define ADS1293_SPI_CS1_PIN 29
#define ADS1293_READY_PIN 31
#define LINE_DET_PIN 10
#include "board/ads_cfg.h"
/*******************************************************************************
* 3µ¼Áª-ADS1293-²âÊÔ *
*******************************************************************************/
APP_TIMER_DEF(m_init_tmr);
APP_TIMER_DEF(m_report_tmr);
ZDATACHANNEL_DEF(m_zhrs, 2 /**/, 1 /*client num*/);
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(2); /**< SPI instance. */
static ads1293_t m_ads1293_0; // U2
// static ads1293_t m_ads1293_1; // U3
static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt);
static void on_service_init(void);
static void zdatachanel_send_log(const char* fmt, ...);
static void three_lead_ecg_ecg_init();
uint32_t get_ready_pin_state_get() { return nrf_gpio_pin_read(ADS1293_READY_PIN); }
static void m_report_tmr_cb(void* p_context) {
static int id = 0;
id++;
#if 0
uint8_t leadoffstate = ads1293_spi_readreg(&m_ads1293_0, TI_ADS1293_ERROR_LOD_REG);
zdatachanel_send_log("%d%d%d%d_%d%d%d%d\n", //
leadoffstate >> 7 & 0x1, leadoffstate >> 6 & 0x1, leadoffstate >> 5 & 0x1, leadoffstate >> 4 & 0x1, //
leadoffstate >> 3 & 0x1, leadoffstate >> 2 & 0x1, leadoffstate >> 1 & 0x1, leadoffstate >> 0 & 0x1); //
#endif
#if 0
uint8_t state = ads1293_spi_readreg(&m_ads1293_0, TI_ADS1293_CONFIG_REG);
zdatachanel_send_log("ads_%d config:%x\n", m_ads1293_0.id, state);
#endif
static bool state = false;
bool now = get_ready_pin_state_get();
if (state != now) {
state = now;
zdatachanel_send_log("%d\n", now);
}
// zdatachanel_send_log("%d\n", id);
}
static void init_tmr_cb(void* p_context) {
nrf_gpio_cfg_input(LINE_DET_PIN, NRF_GPIO_PIN_PULLUP);
three_lead_ecg_ecg_init();
ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_CONFIG_REG, 0x01);
nrf_delay_ms(1000);
ZERROR_CHECK(app_timer_start(m_report_tmr, APP_TIMER_TICKS(1), NULL));
}
int main() {
APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
znordic_init();
NRF_LOG_INFO("compile time :%s", __TIME__);
static zble_module_cfg_t cfg = //
{
.deviceName = "ThreeLeadECG",
.on_service_init = on_service_init,
};
zble_module_init(&cfg);
zble_module_start_adv();
ZERROR_CHECK(app_timer_create(&m_init_tmr, APP_TIMER_MODE_SINGLE_SHOT, init_tmr_cb));
ZERROR_CHECK(app_timer_start(m_init_tmr, APP_TIMER_TICKS(3000), NULL));
ZERROR_CHECK(app_timer_create(&m_report_tmr, APP_TIMER_MODE_REPEATED, m_report_tmr_cb));
znordic_loop();
}
/*******************************************************************************
* UTILS *
*******************************************************************************/
/*******************************************************************************
* CODE *
*******************************************************************************/
static void ads1293_spi_tx_rx_0(uint8_t* tx, uint8_t* rx, uint8_t len) {
nrf_gpio_pin_clear(ADS1293_SPI_CS0_PIN);
nrf_drv_spi_transfer(&spi, tx, len, rx, len);
nrf_gpio_pin_set(ADS1293_SPI_CS0_PIN);
}
static void ads1293_spi_tx_rx_1(uint8_t* tx, uint8_t* rx, uint8_t len) {
nrf_gpio_pin_clear(ADS1293_SPI_CS1_PIN);
nrf_drv_spi_transfer(&spi, tx, len, rx, len);
nrf_gpio_pin_set(ADS1293_SPI_CS1_PIN);
}
static void ads1293_spi_writereg_and_check(ads1293_t* ads, uint8_t addr, uint8_t data) {
uint8_t readbak = 0;
// readonly add
if (addr == 0x19 || addr == 0x1a || addr == 0x1b || addr == 0x1c || addr == 0x40 || addr == 0x30) {
return;
}
ads1293_spi_writereg_and_readbak(ads, addr, data, &readbak);
if (readbak != data) {
zdatachanel_send_log("ads_%d write %x failed,w:%x readbak:%x\n", ads->id, addr, data, readbak);
}
}
static adscfg_t prvads0cfg[] = {
{0x00, 0x00}, //
{0x01, 0x0a}, //
{0x02, 0x1a}, //
{0x03, 0x00}, //
{0x04, 0x00}, //
{0x05, 0x00}, //
{0x06, 0x04}, //
{0x07, 0x0f}, //
{0x08, 0xff}, //
{0x09, 0x00}, //
{0x0a, 0x07}, //
{0x0b, 0x00}, //
{0x0c, 0x04}, //
{0x0d, 0x00}, //
{0x0e, 0x00}, //
{0x0f, 0x00}, //
{0x10, 0x00}, //
{0x11, 0x00}, //
{0x12, 0x04}, //
{0x13, 0x00}, //
{0x14, 0x00}, //
{0x15, 0x00}, //
{0x16, 0x00}, //
{0x17, 0x05}, //
{0x18, 0x00}, //
{0x19, 0x00}, //
{0x1a, 0x00}, //
{0x1b, 0x00}, //
{0x1c, 0x00}, //
{0x1d, 0x00}, //
{0x21, 0x02}, //
{0x22, 0x02}, //
{0x23, 0x02}, //
{0x24, 0x02}, //
{0x25, 0x00}, //
{0x26, 0x00}, //
{0x27, 0x08}, //
{0x28, 0x00}, //
{0x29, 0x00}, //
{0x2a, 0x00}, //
{0x2b, 0x00}, //
{0x2c, 0x00}, //
{0x2d, 0x00}, //
{0x2e, 0x33}, //
{0x2f, 0x30}, //
{0x30, 0x00}, //
{0x31, 0x00}, //
{0x32, 0x00}, //
{0x33, 0x00}, //
{0x34, 0x00}, //
{0x35, 0x00}, //
{0x36, 0x00}, //
{0x37, 0x00}, //
{0x38, 0x00}, //
{0x39, 0x00}, //
{0x3a, 0x00}, //
{0x3b, 0x00}, //
{0x3c, 0x00}, //
{0x3d, 0x00}, //
{0x3e, 0x00}, //
{0x3f, 0x00}, //
{0x40, 0xff}, //
{0x50, 0x00}, //
{0x60, 0x00}, //
{0x62, 0x00}, //
};
void three_lead_ecg_ecg_init() {
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED; // NRF_DRV_SPI_PIN_NOT_USED
spi_config.miso_pin = ADS1293_SPI_MISO_PIN;
spi_config.mosi_pin = ADS1293_SPI_MOSI_PIN;
spi_config.sck_pin = ADS1293_SPI_SCK_PIN;
spi_config.frequency = NRF_DRV_SPI_FREQ_8M;
spi_config.mode = NRF_DRV_SPI_MODE_3;
// spi_config.mode =
ZERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, NULL, NULL));
znrf_gpio_cfg_output(ADS1293_SPI_CS0_PIN, NRF_GPIO_PIN_NOPULL);
znrf_gpio_cfg_output(ADS1293_SPI_CS1_PIN, NRF_GPIO_PIN_NOPULL);
nrf_gpio_cfg_input(ADS1293_READY_PIN, NRF_GPIO_PIN_PULLUP);
nrf_gpio_pin_set(ADS1293_SPI_CS0_PIN);
nrf_gpio_pin_set(ADS1293_SPI_CS1_PIN);
m_ads1293_0.spi_tx_rx = ads1293_spi_tx_rx_0;
m_ads1293_0.id = 0;
// m_ads1293_1.spi_tx_rx = ads1293_spi_tx_rx_1;
// m_ads1293_1.id = 1;
ads1293_spi_init(&m_ads1293_0, ads1293_spi_tx_rx_0);
// ads1293_spi_init(&m_ads1293_1, ads1293_spi_tx_rx_1);
uint8_t revid = ads1293_spi_readreg(&m_ads1293_0, TI_ADS1293_REVID_REG);
zdatachanel_send_log("ads1293_0 revid: %d\n", revid);
// revid = ads1293_spi_readreg(&m_ads1293_1, TI_ADS1293_REVID_REG);
// zdatachanel_send_log("ads1293_1 revid: %d\n", revid);
zdatachanel_send_log("reset ads1293_0\n");
ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_CONFIG_REG, 0);
nrf_delay_ms(1000);
for (uint16_t i = 0; i < ZARRAY_SIZE(prvads0cfg); i++) {
ads1293_spi_writereg_and_check(&m_ads1293_0, prvads0cfg[i].add, prvads0cfg[i].data);
zdatachanel_send_log("[%d]ads1293_0 write %x:%x\n", i, prvads0cfg[i].add, prvads0cfg[i].data);
}
// for (uint16_t i = 0; i < ZARRAY_SIZE(ads1cfg); i++) {
// ads1293_spi_writereg_and_check(&m_ads1293_1, ads1cfg[i].add, ads1cfg[i].data);
// }
// ads1293_spi_writereg(&m_ads1293_1, TI_ADS1293_CONFIG_REG, 0x01);
}
static void zdatachanel_send_log(const char* fmt, ...) {
static char tx[256] = {0};
static uint16_t len = 0;
va_list args;
va_start(args, fmt);
len = vsprintf(tx, fmt, args);
int ret;
do {
ret = zdatachannel_data_send((uint8_t*)tx, &len);
} while (ret != 0);
va_end(args);
}
static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {}
static void on_service_init(void) {
ZLOGI("init zdatachannel service");
zdatachannel_init_t zdatachannle_init;
memset(&zdatachannle_init, 0, sizeof(zdatachannle_init));
zdatachannle_init.data_handler = zdatachannel_data_handler;
ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
}
#endif

2
app/src/basic/ads1293/ads1293.c

@ -82,7 +82,7 @@ void ads1293_read_ecg(ads1293_t* ads, uint32_t ch, uint32_t* data) {
ads1293_spi_autoinc_readreg(ads, add, readbak, 3); ads1293_spi_autoinc_readreg(ads, add, readbak, 3);
*data = 0; *data = 0;
*data = (readbak[0] << 16) + (readbak[0] << 8) + (readbak[0] << 0);
*data = ((uint32_t)readbak[0] << 16) + ((uint32_t)readbak[1] << 8) + ((uint32_t)readbak[2] << 0);
} }
void ads1293_start_conversion(ads1293_t* ads) { void ads1293_start_conversion(ads1293_t* ads) {

447
app/src/main.c

@ -23,250 +23,7 @@
int main() { return 0; } int main() { return 0; }
#endif #endif
#if 0
#define ADS1293_SPI_SCK_PIN (32 + 9)
#define ADS1293_SPI_MOSI_PIN 15
#define ADS1293_SPI_MISO_PIN 20
#define ADS1293_SPI_CS0_PIN 3
#define ADS1293_SPI_CS1_PIN 29
#define ADS1293_READY_PIN 31
#define LINE_DET_PIN 10
#include "board/ads_cfg.h"
/*******************************************************************************
* 3µ¼Áª-ADS1293-²âÊÔ *
*******************************************************************************/
APP_TIMER_DEF(m_init_tmr);
APP_TIMER_DEF(m_report_tmr);
ZDATACHANNEL_DEF(m_zhrs, 2 /**/, 1 /*client num*/);
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(2); /**< SPI instance. */
static ads1293_t m_ads1293_0; // U2
// static ads1293_t m_ads1293_1; // U3
static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt);
static void on_service_init(void);
static void zdatachanel_send_log(const char* fmt, ...);
static void three_lead_ecg_ecg_init();
uint32_t get_ready_pin_state_get() { return nrf_gpio_pin_read(ADS1293_READY_PIN); }
static void m_report_tmr_cb(void* p_context) {
static int id = 0;
id++;
#if 0
uint8_t leadoffstate = ads1293_spi_readreg(&m_ads1293_0, TI_ADS1293_ERROR_LOD_REG);
zdatachanel_send_log("%d%d%d%d_%d%d%d%d\n", //
leadoffstate >> 7 & 0x1, leadoffstate >> 6 & 0x1, leadoffstate >> 5 & 0x1, leadoffstate >> 4 & 0x1, //
leadoffstate >> 3 & 0x1, leadoffstate >> 2 & 0x1, leadoffstate >> 1 & 0x1, leadoffstate >> 0 & 0x1); //
#endif
#if 0
uint8_t state = ads1293_spi_readreg(&m_ads1293_0, TI_ADS1293_CONFIG_REG);
zdatachanel_send_log("ads_%d config:%x\n", m_ads1293_0.id, state);
#endif
static bool state = false;
bool now = get_ready_pin_state_get();
if (state != now) {
state = now;
zdatachanel_send_log("%d\n", now);
}
// zdatachanel_send_log("%d\n", id);
}
static void init_tmr_cb(void* p_context) {
nrf_gpio_cfg_input(LINE_DET_PIN, NRF_GPIO_PIN_PULLUP);
three_lead_ecg_ecg_init();
ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_CONFIG_REG, 0x01);
nrf_delay_ms(1000);
ZERROR_CHECK(app_timer_start(m_report_tmr, APP_TIMER_TICKS(1), NULL));
}
int main() {
APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
znordic_init();
NRF_LOG_INFO("compile time :%s", __TIME__);
static zble_module_cfg_t cfg = //
{
.deviceName = "ThreeLeadECG",
.on_service_init = on_service_init,
};
zble_module_init(&cfg);
zble_module_start_adv();
ZERROR_CHECK(app_timer_create(&m_init_tmr, APP_TIMER_MODE_SINGLE_SHOT, init_tmr_cb));
ZERROR_CHECK(app_timer_start(m_init_tmr, APP_TIMER_TICKS(3000), NULL));
ZERROR_CHECK(app_timer_create(&m_report_tmr, APP_TIMER_MODE_REPEATED, m_report_tmr_cb));
znordic_loop();
}
/*******************************************************************************
* UTILS *
*******************************************************************************/
/*******************************************************************************
* CODE *
*******************************************************************************/
static void ads1293_spi_tx_rx_0(uint8_t* tx, uint8_t* rx, uint8_t len) {
nrf_gpio_pin_clear(ADS1293_SPI_CS0_PIN);
nrf_drv_spi_transfer(&spi, tx, len, rx, len);
nrf_gpio_pin_set(ADS1293_SPI_CS0_PIN);
}
static void ads1293_spi_tx_rx_1(uint8_t* tx, uint8_t* rx, uint8_t len) {
nrf_gpio_pin_clear(ADS1293_SPI_CS1_PIN);
nrf_drv_spi_transfer(&spi, tx, len, rx, len);
nrf_gpio_pin_set(ADS1293_SPI_CS1_PIN);
}
static void ads1293_spi_writereg_and_check(ads1293_t* ads, uint8_t addr, uint8_t data) {
uint8_t readbak = 0;
// readonly add
if (addr == 0x19 || addr == 0x1a || addr == 0x1b || addr == 0x1c || addr == 0x40 || addr == 0x30) {
return;
}
ads1293_spi_writereg_and_readbak(ads, addr, data, &readbak);
if (readbak != data) {
zdatachanel_send_log("ads_%d write %x failed,w:%x readbak:%x\n", ads->id, addr, data, readbak);
}
}
static adscfg_t prvads0cfg[] = {
{0x00, 0x00}, //
{0x01, 0x0a}, //
{0x02, 0x1a}, //
{0x03, 0x00}, //
{0x04, 0x00}, //
{0x05, 0x00}, //
{0x06, 0x04}, //
{0x07, 0x0f}, //
{0x08, 0xff}, //
{0x09, 0x00}, //
{0x0a, 0x07}, //
{0x0b, 0x00}, //
{0x0c, 0x04}, //
{0x0d, 0x00}, //
{0x0e, 0x00}, //
{0x0f, 0x00}, //
{0x10, 0x00}, //
{0x11, 0x00}, //
{0x12, 0x04}, //
{0x13, 0x00}, //
{0x14, 0x00}, //
{0x15, 0x00}, //
{0x16, 0x00}, //
{0x17, 0x05}, //
{0x18, 0x00}, //
{0x19, 0x00}, //
{0x1a, 0x00}, //
{0x1b, 0x00}, //
{0x1c, 0x00}, //
{0x1d, 0x00}, //
{0x21, 0x02}, //
{0x22, 0x02}, //
{0x23, 0x02}, //
{0x24, 0x02}, //
{0x25, 0x00}, //
{0x26, 0x00}, //
{0x27, 0x08}, //
{0x28, 0x00}, //
{0x29, 0x00}, //
{0x2a, 0x00}, //
{0x2b, 0x00}, //
{0x2c, 0x00}, //
{0x2d, 0x00}, //
{0x2e, 0x33}, //
{0x2f, 0x30}, //
{0x30, 0x00}, //
{0x31, 0x00}, //
{0x32, 0x00}, //
{0x33, 0x00}, //
{0x34, 0x00}, //
{0x35, 0x00}, //
{0x36, 0x00}, //
{0x37, 0x00}, //
{0x38, 0x00}, //
{0x39, 0x00}, //
{0x3a, 0x00}, //
{0x3b, 0x00}, //
{0x3c, 0x00}, //
{0x3d, 0x00}, //
{0x3e, 0x00}, //
{0x3f, 0x00}, //
{0x40, 0xff}, //
{0x50, 0x00}, //
{0x60, 0x00}, //
{0x62, 0x00}, //
};
void three_lead_ecg_ecg_init() {
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED; // NRF_DRV_SPI_PIN_NOT_USED
spi_config.miso_pin = ADS1293_SPI_MISO_PIN;
spi_config.mosi_pin = ADS1293_SPI_MOSI_PIN;
spi_config.sck_pin = ADS1293_SPI_SCK_PIN;
spi_config.frequency = NRF_DRV_SPI_FREQ_8M;
spi_config.mode = NRF_DRV_SPI_MODE_3;
// spi_config.mode =
ZERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, NULL, NULL));
znrf_gpio_cfg_output(ADS1293_SPI_CS0_PIN, NRF_GPIO_PIN_NOPULL);
znrf_gpio_cfg_output(ADS1293_SPI_CS1_PIN, NRF_GPIO_PIN_NOPULL);
nrf_gpio_cfg_input(ADS1293_READY_PIN, NRF_GPIO_PIN_PULLUP);
nrf_gpio_pin_set(ADS1293_SPI_CS0_PIN);
nrf_gpio_pin_set(ADS1293_SPI_CS1_PIN);
m_ads1293_0.spi_tx_rx = ads1293_spi_tx_rx_0;
m_ads1293_0.id = 0;
// m_ads1293_1.spi_tx_rx = ads1293_spi_tx_rx_1;
// m_ads1293_1.id = 1;
ads1293_spi_init(&m_ads1293_0, ads1293_spi_tx_rx_0);
// ads1293_spi_init(&m_ads1293_1, ads1293_spi_tx_rx_1);
uint8_t revid = ads1293_spi_readreg(&m_ads1293_0, TI_ADS1293_REVID_REG);
zdatachanel_send_log("ads1293_0 revid: %d\n", revid);
// revid = ads1293_spi_readreg(&m_ads1293_1, TI_ADS1293_REVID_REG);
// zdatachanel_send_log("ads1293_1 revid: %d\n", revid);
zdatachanel_send_log("reset ads1293_0\n");
ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_CONFIG_REG, 0);
nrf_delay_ms(1000);
for (uint16_t i = 0; i < ZARRAY_SIZE(prvads0cfg); i++) {
ads1293_spi_writereg_and_check(&m_ads1293_0, prvads0cfg[i].add, prvads0cfg[i].data);
zdatachanel_send_log("[%d]ads1293_0 write %x:%x\n", i, prvads0cfg[i].add, prvads0cfg[i].data);
}
// for (uint16_t i = 0; i < ZARRAY_SIZE(ads1cfg); i++) {
// ads1293_spi_writereg_and_check(&m_ads1293_1, ads1cfg[i].add, ads1cfg[i].data);
// }
// ads1293_spi_writereg(&m_ads1293_1, TI_ADS1293_CONFIG_REG, 0x01);
}
static void zdatachanel_send_log(const char* fmt, ...) {
static char tx[256] = {0};
static uint16_t len = 0;
va_list args;
va_start(args, fmt);
len = vsprintf(tx, fmt, args);
int ret;
do {
ret = zdatachannel_data_send((uint8_t*)tx, &len);
} while (ret != 0);
va_end(args);
}
static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {}
static void on_service_init(void) {
ZLOGI("init zdatachannel service");
zdatachannel_init_t zdatachannle_init;
memset(&zdatachannle_init, 0, sizeof(zdatachannle_init));
zdatachannle_init.data_handler = zdatachannel_data_handler;
ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
}
#endif
#if 1 #if 1
@ -330,20 +87,16 @@ static void m_report_tmr_cb(void* p_context) {
uint8_t state = ads1293_spi_readreg(&m_ads1293_0, TI_ADS1293_CONFIG_REG); uint8_t state = ads1293_spi_readreg(&m_ads1293_0, TI_ADS1293_CONFIG_REG);
zdatachanel_send_log("ads_%d config:%x\n", m_ads1293_0.id, state); zdatachanel_send_log("ads_%d config:%x\n", m_ads1293_0.id, state);
#endif #endif
#if 0
static bool state = false; static bool state = false;
bool now = get_ready_pin_state_get(); bool now = get_ready_pin_state_get();
if (state != now) { if (state != now) {
state = now; state = now;
zdatachanel_send_log("%d\n", now); zdatachanel_send_log("%d\n", now);
} }
#endif
} }
static void init_tmr_cb(void* p_context) {
nrf_gpio_cfg_input(LINE_DET_PIN, NRF_GPIO_PIN_PULLUP);
three_lead_ecg_ecg_init();
ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_CONFIG_REG, 0x01);
ZERROR_CHECK(app_timer_start(m_report_tmr, APP_TIMER_TICKS(0.1), NULL));
}
static void on_service_init(void) { static void on_service_init(void) {
ZLOGI("init zdatachannel service"); ZLOGI("init zdatachannel service");
zdatachannel_init_t zdatachannle_init; zdatachannel_init_t zdatachannle_init;
@ -351,6 +104,23 @@ static void on_service_init(void) {
zdatachannle_init.data_handler = NULL; zdatachannle_init.data_handler = NULL;
ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init)); ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
} }
static int changecount = 0;
void dump_state() {
static uint32_t last = 0;
uint32_t nows = znordic_rtc_gettime_s();
if (nows != last) {
zdatachanel_send_log("%d\n", changecount);
uint8_t leadoffstate = ads1293_spi_readreg(&m_ads1293_0, TI_ADS1293_ERROR_LOD_REG);
zdatachanel_send_log("%d%d%d%d_%d%d%d%d\n", //
leadoffstate >> 7 & 0x1, leadoffstate >> 6 & 0x1, leadoffstate >> 5 & 0x1, leadoffstate >> 4 & 0x1, //
leadoffstate >> 3 & 0x1, leadoffstate >> 2 & 0x1, leadoffstate >> 1 & 0x1, leadoffstate >> 0 & 0x1); //
last = nows;
changecount = 0;
}
}
int main() { int main() {
APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20); APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
znordic_init(); znordic_init();
@ -367,11 +137,6 @@ int main() {
three_lead_ecg_ecg_init(); three_lead_ecg_ecg_init();
ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_CONFIG_REG, 0x01); ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_CONFIG_REG, 0x01);
// ZERROR_CHECK(app_timer_create(&m_init_tmr, APP_TIMER_MODE_SINGLE_SHOT, init_tmr_cb));
// ZERROR_CHECK(app_timer_create(&m_report_tmr, APP_TIMER_MODE_REPEATED, m_report_tmr_cb));
// ZERROR_CHECK(app_timer_start(m_init_tmr, APP_TIMER_TICKS(1), NULL));
// ZERROR_CHECK(app_timer_start(m_report_tmr, APP_TIMER_TICKS(10), NULL));
while (true) { while (true) {
app_sched_execute(); app_sched_execute();
if (NRF_LOG_PROCESS() == false) { if (NRF_LOG_PROCESS() == false) {
@ -381,8 +146,20 @@ int main() {
bool now = get_ready_pin_state_get(); bool now = get_ready_pin_state_get();
if (state != now) { if (state != now) {
state = now; state = now;
zdatachanel_send_log("%d\n", now);
changecount++;
if (now) {
uint32_t val = 0;
ads1293_read_ecg(&m_ads1293_0, 1, &val);
zdatachanel_send_log("%d\n", val);
} }
// zdatachanel_send_log("%d\n", now);
}
// dump_state();
#if 0
#endif
} }
// znordic_loop(); // znordic_loop();
@ -415,74 +192,107 @@ static void ads1293_spi_writereg_and_check(ads1293_t* ads, uint8_t addr, uint8_t
} }
} }
// static adscfg_t prvads0cfg[] = {
// {0x00, 0x00}, //
// {0x01, 0x0a}, //
// {0x02, 0x1a}, //
// {0x03, 0x00}, //
// {0x04, 0x00}, //
// {0x05, 0x00}, //
// {0x06, 0x04}, //
// {0x07, 0x0f}, //
// {0x08, 0xff}, //
// {0x09, 0x00}, //
// {0x0a, 0x07}, //
// {0x0b, 0x00}, //
// {0x0c, 0x04}, //
// {0x0d, 0x00}, //
// {0x0e, 0x00}, //
// {0x0f, 0x00}, //
// {0x10, 0x00}, //
// {0x11, 0x00}, //
// {0x12, 0x04}, //
// {0x13, 0x00}, //
// {0x14, 0x00}, //
// {0x15, 0x00}, //
// {0x16, 0x00}, //
// {0x17, 0x05}, //
// {0x18, 0x00}, //
// {0x19, 0x00}, //
// {0x1a, 0x00}, //
// {0x1b, 0x00}, //
// {0x1c, 0x00}, //
// {0x1d, 0x00}, //
// {0x21, 0x02}, //
// {0x22, 0x02}, //
// {0x23, 0x02}, //
// {0x24, 0x02}, //
// {0x25, 0x00}, //
// {0x26, 0x00}, //
// {0x27, 0x08}, //
// {0x28, 0x00}, //
// {0x29, 0x00}, //
// {0x2a, 0x00}, //
// {0x2b, 0x00}, //
// {0x2c, 0x00}, //
// {0x2d, 0x00}, //
// {0x2e, 0x33}, //
// {0x2f, 0x30}, //
// {0x30, 0x00}, //
// {0x31, 0x00}, //
// {0x32, 0x00}, //
// {0x33, 0x00}, //
// {0x34, 0x00}, //
// {0x35, 0x00}, //
// {0x36, 0x00}, //
// {0x37, 0x00}, //
// {0x38, 0x00}, //
// {0x39, 0x00}, //
// {0x3a, 0x00}, //
// {0x3b, 0x00}, //
// {0x3c, 0x00}, //
// {0x3d, 0x00}, //
// {0x3e, 0x00}, //
// {0x3f, 0x00}, //
// {0x40, 0xff}, //
// {0x50, 0x00}, //
// {0x60, 0x00}, //
// {0x62, 0x00}, //
// };
static adscfg_t prvads0cfg[] = { static adscfg_t prvads0cfg[] = {
{0x00, 0x00}, //
{0x01, 0x0a}, //
{0x02, 0x1a}, //
{0x03, 0x00}, //
{0x04, 0x00}, //
{0x05, 0x00}, //
{0x06, 0x04}, //
{0x07, 0x0f}, //
{0x08, 0xff}, //
{0x09, 0x00}, //
{0x0a, 0x07}, //
{0x0b, 0x00}, //
{0x0c, 0x04}, //
{0x0d, 0x00}, //
{0x0e, 0x00}, //
{0x0f, 0x00}, //
{0x10, 0x00}, //
{0x11, 0x00}, //
{0x01, 0x11}, //
{0x02, 0x19}, //
{0x0A, 0x07}, //
{0x0C, 0x04}, //
{0x12, 0x04}, // {0x12, 0x04}, //
{0x13, 0x00}, //
{0x14, 0x00}, //
{0x15, 0x00}, //
{0x16, 0x00}, //
{0x17, 0x05}, //
{0x18, 0x00}, //
{0x19, 0x00}, //
{0x1a, 0x00}, //
{0x1b, 0x00}, //
{0x1c, 0x00}, //
{0x1d, 0x00}, //
{0x21, 0x02}, //
{0x22, 0x02}, //
{0x23, 0x02}, //
{0x24, 0x02}, //
{0x25, 0x00}, //
{0x26, 0x00}, //
{0x14, 0x24}, //
{0x21, 16}, //
{0x22, 16}, //
{0x23, 16}, //
{0x27, 0x08}, // {0x27, 0x08}, //
{0x28, 0x00}, //
{0x29, 0x00}, //
{0x2a, 0x00}, //
{0x2b, 0x00}, //
{0x2c, 0x00}, //
{0x2d, 0x00}, //
{0x2e, 0x33}, //
{0x2f, 0x30}, //
{0x30, 0x00}, //
{0x31, 0x00}, //
{0x32, 0x00}, //
{0x33, 0x00}, //
{0x34, 0x00}, //
{0x35, 0x00}, //
{0x36, 0x00}, //
{0x37, 0x00}, //
{0x38, 0x00}, //
{0x39, 0x00}, //
{0x3a, 0x00}, //
{0x3b, 0x00}, //
{0x3c, 0x00}, //
{0x3d, 0x00}, //
{0x3e, 0x00}, //
{0x3f, 0x00}, //
{0x40, 0xff}, //
{0x50, 0x00}, //
{0x60, 0x00}, //
{0x62, 0x00}, //
{0x2F, 0x30}, //
//
// {0x06, 0x14}, // LOD
// {0x07, 0x07}, //
// {0x08, 0xFF}, //
}; };
void config_lod(uint8_t aclvl_lod, uint8_t selac_lod, uint8_t shdn_lod, uint8_t acad_lod) {
uint8_t reg = 0;
reg |= aclvl_lod;
reg |= selac_lod << 2;
reg |= shdn_lod << 3;
reg |= acad_lod << 4;
ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_LOD_CN_REG, reg);
}
void enable_lod(void) {
uint8_t reg = ads1293_spi_readreg(&m_ads1293_0, TI_ADS1293_CONFIG_REG);
reg |= 1 << 3;
ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_LOD_EN_REG, reg);
}
void three_lead_ecg_ecg_init() { void three_lead_ecg_ecg_init() {
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG; nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED; // NRF_DRV_SPI_PIN_NOT_USED spi_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED; // NRF_DRV_SPI_PIN_NOT_USED
@ -516,6 +326,7 @@ void three_lead_ecg_ecg_init() {
zdatachanel_send_log("reset ads1293_0\n"); zdatachanel_send_log("reset ads1293_0\n");
ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_CONFIG_REG, 0); ads1293_spi_writereg(&m_ads1293_0, TI_ADS1293_CONFIG_REG, 0);
nrf_delay_ms(1000);
for (uint16_t i = 0; i < ZARRAY_SIZE(prvads0cfg); i++) { for (uint16_t i = 0; i < ZARRAY_SIZE(prvads0cfg); i++) {
ads1293_spi_writereg_and_check(&m_ads1293_0, prvads0cfg[i].add, prvads0cfg[i].data); ads1293_spi_writereg_and_check(&m_ads1293_0, prvads0cfg[i].add, prvads0cfg[i].data);

Loading…
Cancel
Save