|
|
@ -90,6 +90,9 @@ uint8_t ads129X_rw_reg(uint8_t cmd, uint8_t data) { |
|
|
|
return rx; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t ads129X_read_reg(uint8_t add) { return ads129X_rw_reg(ADS129X_COMMAND_RREG | add, 0); } |
|
|
|
void ads129X_write_reg(uint8_t add, uint8_t data) { ads129X_rw_reg(ADS129X_COMMAND_WREG | add, data); } |
|
|
|
|
|
|
|
/* 从指定寄存器开始读写一定数量的寄存器 */ |
|
|
|
void ads129X_write_multiregs(uint8_t reg, uint8_t* ch, uint8_t size) { |
|
|
|
uint8_t i; |
|
|
@ -170,6 +173,16 @@ static bool ads129x_write_reg(ads129x_regs_t* writeval) { |
|
|
|
/*********************************************************************************************************************** |
|
|
|
* EXTERN * |
|
|
|
***********************************************************************************************************************/ |
|
|
|
void ads129x_read_data_loop() { |
|
|
|
ads129x_capture_data_t capture_data; |
|
|
|
while (true) { |
|
|
|
while (ADS129X_DRDY_GET()) |
|
|
|
; |
|
|
|
|
|
|
|
ads129x_read_data(&capture_data); |
|
|
|
ZLOGI("{%d} %x", capture_data.ch1data, capture_data.loffstate); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t ads129x_init() { |
|
|
|
/** |
|
|
@ -194,28 +207,8 @@ uint8_t ads129x_init() { |
|
|
|
nrf_gpio_pin_set(ADS1291_PWDN_PIN); |
|
|
|
nrf_delay_ms(2000); |
|
|
|
|
|
|
|
ads129x_start_capture(true); |
|
|
|
// char txdata[] = {1, 2, 3, 4}; |
|
|
|
while (true) /* 识别芯片型号,1291:0x52 */ |
|
|
|
{ |
|
|
|
uint8_t id = ads129X_rw_reg(ADS129X_COMMAND_RREG | ADS129X_REG_ID, 0); |
|
|
|
// nrf_log_backend_uart_tx_raw(txdata, 4); |
|
|
|
// znordic_force_flush_log(); |
|
|
|
|
|
|
|
ZLOGI("ads129X id: %x", id); |
|
|
|
nrf_delay_ms(1000); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ads129x_read_data_loop() { |
|
|
|
ads129x_capture_data_t capture_data; |
|
|
|
while (true) { |
|
|
|
while (ADS129X_DRDY_GET()) |
|
|
|
; |
|
|
|
|
|
|
|
ads129x_read_data(&capture_data); |
|
|
|
ZLOGI("{%d}", capture_data.ch0data); |
|
|
|
} |
|
|
|
ads129x_start_capture(false); |
|
|
|
ads129x_read_data_loop(); |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t ads129x_start_capture(bool test) { |
|
|
@ -234,6 +227,15 @@ uint8_t ads129x_start_capture(bool test) { |
|
|
|
regcache.rld_sens = 0x20; |
|
|
|
regcache.loff_sens = 0x03; |
|
|
|
|
|
|
|
/* 导联脱落比较器开,内部2.42v参考电压 */ |
|
|
|
regcache.cfg2 = ADS129X_SET_BITS(regcache.cfg2, ADS129X_PDB_LOFF_COMP, ADS129X_PDB_LOFF_COMP_ON); |
|
|
|
regcache.cfg2 = ADS129X_SET_BITS(regcache.cfg2, ADS129X_PDB_REFBUF, ADS129X_PDB_REFBUF_ON); |
|
|
|
regcache.cfg2 = ADS129X_SET_BITS(regcache.cfg2, ADS129X_VREF_4V, ADS129X_VREF_2420MV); |
|
|
|
|
|
|
|
/* 通道二导联脱落检测功能开 */ |
|
|
|
regcache.loff_sens = ADS129X_SET_BITS(regcache.loff_sens, ADS129X_LOFF2N, ADS129X_LOFF2N_ON); |
|
|
|
regcache.loff_sens = ADS129X_SET_BITS(regcache.loff_sens, ADS129X_LOFF2P, ADS129X_LOFF2P_ON); |
|
|
|
|
|
|
|
if (test) { |
|
|
|
regcache.cfg2 = ADS129X_SET_BITS(regcache.cfg2, ADS129X_INT_TEST, ADS129X_INT_TEST_ON); |
|
|
|
regcache.cfg2 = ADS129X_SET_BITS(regcache.cfg2, ADS129X_INT_FREQ, ADS129X_INT_FREQ_AC); |
|
|
@ -246,8 +248,6 @@ uint8_t ads129x_start_capture(bool test) { |
|
|
|
port_delay_ms(10); |
|
|
|
ads129X_send_cmd(ADS129X_COMMAND_START); /* 发送开始数据转换(等效于拉高START引脚) */ |
|
|
|
port_delay_ms(10); |
|
|
|
|
|
|
|
ads129x_read_data_loop(); |
|
|
|
} |
|
|
|
|
|
|
|
static int32_t i24toi32(uint8_t* p_i32) { |
|
|
@ -281,16 +281,23 @@ void ads129x_read_data(ads129x_capture_data_t* capture_data) { |
|
|
|
* 24bit ch1 MSB |
|
|
|
* |
|
|
|
*/ |
|
|
|
capture_data->loffstate = rddata[0]; |
|
|
|
capture_data->gpio0 = rddata[0]; |
|
|
|
capture_data->gpio1 = rddata[0]; |
|
|
|
capture_data->ch0data = i24toi32(&rddata[3]); |
|
|
|
capture_data->ch1data = i24toi32(&rddata[6]); |
|
|
|
uint32_t status = (((uint32_t)rddata[0]) << 16) | (((uint32_t)rddata[1]) << 8) | ((uint32_t)rddata[2]); |
|
|
|
|
|
|
|
capture_data->loffstate = (status >> (13 + 2)) & 0x1f; |
|
|
|
capture_data->gpio0 = status >> (14); |
|
|
|
capture_data->gpio1 = status >> (13); |
|
|
|
|
|
|
|
capture_data->ch1data = i24toi32(&rddata[3]); |
|
|
|
capture_data->ch2data = i24toi32(&rddata[6]); |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t ads129x_get_lead_off_state() { |
|
|
|
// FLIP2,FLIP1,LOFF2N,LOFF2P,LOFF1N,LOFF1P |
|
|
|
uint8_t leadoffstate = ads129X_read_reg(ADS129X_REG_LOFFSTAT); |
|
|
|
return leadoffstate; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t ads129x_enter_low_power_mode() { return 0; } |
|
|
|
uint8_t ads129x_enter_lead_off_detect_mode() { return 0; } |
|
|
|
|
|
|
|
uint8_t ads129x_data_is_ready() { return ADS129X_DRDY_GET(); } |
|
|
|
|
|
|
|
uint8_t ads129x_get_lead_off_state() { return 0; } |