Browse Source

ads1293 spi通信成功

3lead_uart_test_ok_version
zhaohe 1 year ago
parent
commit
536fa9ce26
  1. 90
      app/main.c
  2. 2
      app/src/basic/ads1293/ads1293.c
  3. 18
      app/src/three_lead/three_lead_board.c

90
app/main.c

@ -19,7 +19,7 @@
#include "nrf_uarte.h" #include "nrf_uarte.h"
#endif #endif
#if 1
#if 0
static void test_tx_timer_cb(void* p_context) { static void test_tx_timer_cb(void* p_context) {
static uint32_t data; static uint32_t data;
data++; data++;
@ -312,4 +312,92 @@ void main() {
ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL)); ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
znordic_loop(); znordic_loop();
} }
#endif
#if 1
/*******************************************************************************
* 3-ADS1293- *
*******************************************************************************/
static void test_tx_timer_cb(void* p_context) {
static uint32_t data;
data++;
ZLOGI("tim cb %d", data);
// ThreeLeadECG_sdcard_connect2_ext_usb_sdcard_driver_ic_reset();
}
extern uint32_t g_nrf_log_tx_pin;
APP_TIMER_DEF(m_test_tx_timer);
void main() {
APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
// ThreeLeadECG_sdcard_base_init();
znordic_init();
ThreeLeadECG_ecg_init();
NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(3000), NULL));
znordic_loop();
}
#endif
#if 0
/*******************************************************************************
* 3-led测试 *
*******************************************************************************/
static void test_tx_timer_cb(void* p_context) {
static uint32_t data;
data++;
ZLOGI("test_tx_timer_cb %d", data);
ThreeLeadECG_led_green_set_state(data % 2 == 0);
}
extern uint32_t g_nrf_log_tx_pin;
APP_TIMER_DEF(m_test_tx_timer);
void main() {
APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
znordic_init();
NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
NRF_LOG_INTERNAL_FLUSH();
ThreeLeadECG_led_init();
ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
znordic_loop();
}
#endif
#if 0
/*******************************************************************************
* 3- *
*******************************************************************************/
static void test_tx_timer_cb(void* p_context) {
static uint32_t data;
data++;
int16_t mv = ThreeLeadECG_battery_get_adc_val() * 1.0 / 4096 * 3.3 * 1000 / 2.0 * 3;
ZLOGI("battery:%d", mv);
}
extern uint32_t g_nrf_log_tx_pin;
APP_TIMER_DEF(m_test_tx_timer);
void main() {
APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
znordic_init();
NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
NRF_LOG_INTERNAL_FLUSH();
ThreeLeadECG_adc_module_init();
ThreeLeadECG_battery_init();
ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
znordic_loop();
}
#endif #endif

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

@ -27,7 +27,7 @@ uint8_t ads1293_spi_readreg(ads1293_t* ch, uint8_t addr) {
txcache[1] = 0; txcache[1] = 0;
uint8_t rxcache[2]; uint8_t rxcache[2];
ch->spi_tx_rx(txcache, rxcache, 2); ch->spi_tx_rx(txcache, rxcache, 2);
return txcache[1];
return rxcache[1];
} }
void ads1293_spi_autoinc_writereg(ads1293_t* ch, uint8_t addr, uint8_t* data, uint8_t len) { // void ads1293_spi_autoinc_writereg(ads1293_t* ch, uint8_t addr, uint8_t* data, uint8_t len) { //

18
app/src/three_lead/three_lead_board.c

@ -16,7 +16,7 @@
#define LED_GREEN_PIN 9 #define LED_GREEN_PIN 9
#define BATTERY_ADC_PIN NRF_SAADC_INPUT_AIN2
#define BATTERY_ADC_PIN NRF_SAADC_INPUT_AIN0
#define BATTERY_ADC_CHANNEL 1 // 不重复即可 #define BATTERY_ADC_CHANNEL 1 // 不重复即可
#define BUTTON_PIN 0 #define BUTTON_PIN 0
@ -33,6 +33,12 @@
#define SDCARD_USBDRIVER_IC_RESET_PIN 28 #define SDCARD_USBDRIVER_IC_RESET_PIN 28
#define SDCARD_POWER_CTRL_PIN 30 #define SDCARD_POWER_CTRL_PIN 30
#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
/******************************************************************************* /*******************************************************************************
* TOOLS * * TOOLS *
*******************************************************************************/ *******************************************************************************/
@ -355,11 +361,6 @@ void ThreeLeadECG_sdcard_umount() {
/******************************************************************************* /*******************************************************************************
* ecg * * ecg *
*******************************************************************************/ *******************************************************************************/
#define ADS1293_SPI_MISO_PIN 31
#define ADS1293_SPI_CS0_PIN 20
#define ADS1293_SPI_CS1_PIN 20
#define ADS1293_SPI_SCK_PIN 29
#define ADS1293_SPI_MOSI_PIN 30
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(0); /**< SPI instance. */ static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(0); /**< SPI instance. */
@ -384,11 +385,12 @@ void ThreeLeadECG_ecg_init() {
spi_config.mosi_pin = ADS1293_SPI_MOSI_PIN; spi_config.mosi_pin = ADS1293_SPI_MOSI_PIN;
spi_config.sck_pin = ADS1293_SPI_SCK_PIN; spi_config.sck_pin = ADS1293_SPI_SCK_PIN;
spi_config.frequency = NRF_DRV_SPI_FREQ_1M; spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
spi_config.mode = NRF_DRV_SPI_MODE_3;
// spi_config.mode = // spi_config.mode =
ZERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, NULL, NULL)); ZERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, NULL, NULL));
nrf_gpio_cfg_input(ADS1293_SPI_CS0_PIN, NRF_GPIO_PIN_NOPULL);
nrf_gpio_cfg_input(ADS1293_SPI_CS1_PIN, NRF_GPIO_PIN_NOPULL);
znrf_gpio_cfg_output(ADS1293_SPI_CS0_PIN, NRF_GPIO_PIN_PULLUP);
znrf_gpio_cfg_output(ADS1293_SPI_CS1_PIN, NRF_GPIO_PIN_PULLUP);
nrf_gpio_pin_set(ADS1293_SPI_CS0_PIN); nrf_gpio_pin_set(ADS1293_SPI_CS0_PIN);
nrf_gpio_pin_set(ADS1293_SPI_CS1_PIN); nrf_gpio_pin_set(ADS1293_SPI_CS1_PIN);

Loading…
Cancel
Save