I’m using esp32-c6 and ads1292r to acquire ECG data. I have successfully established communication with the ADS1292R through SPI and am able to write to and read from the ADS1292R registers. I also using gpio interrupt to receive sample data from ads1292r.
static void IRAM_ATTR gpio_isr_handler(void *arg)
{
uint32_t gpio_num = (uint32_t)arg;
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
}
static void gpio_task(void *arg)
{
uint32_t io_num;
uint8_t val[9] = {0};
for (;;)
{
if (xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY))
{
for (int i = 0; i < 9; i++)
{
val[i] = ads1292r_receive_data(spi_handle);
}
printf("%x %x %x %x %x %x %x %x %x n", val[0], val[1], val[2],
val[3], val[4], val[5],
val[6], val[7], val[8]);
usleep(3000);
}
}
}
void app_main(void)
{
// gpio config
gpio_config_t io_conf;
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 0;
gpio_config(&io_conf);
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = BIT64(GPIO_DRDY);
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 1;
io_conf.intr_type = GPIO_INTR_NEGEDGE;
gpio_config(&io_conf);
// gpio isr
gpio_evt_queue = xQueueCreate(100, sizeof(uint32_t));
xTaskCreate(gpio_task, "gpio_task", 4096, NULL, 15, NULL);
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
gpio_isr_handler_add(GPIO_DRDY, gpio_isr_handler, (void *)GPIO_DRDY);
// uart config
uart_config_t uart_config = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = UART_SCLK_DEFAULT,
};
uart_driver_install(UART_NUM_0, 512 * 2, 0, 0, NULL, 0);
uart_param_config(UART_NUM_0, &uart_config);
uart_set_pin(UART_NUM_0, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
// spi config
spi_bus_config_t spi_bus_cfg = {
.mosi_io_num = GPIO_MOSI,
.miso_io_num = GPIO_MISO,
.sclk_io_num = GPIO_SCLK,
.quadhd_io_num = -1,
.quadwp_io_num = -1,
};
spi_bus_initialize(SPI2_HOST, &spi_bus_cfg, SPI_DMA_CH_AUTO);
spi_device_interface_config_t dev_cfg = {
.clock_speed_hz = 1 * 1000 * 1000,
.mode = 1,
.spics_io_num = -1,
.queue_size = 1,
};
spi_bus_add_device(SPI2_HOST, &dev_cfg, &spi_handle);
ads1292r_init(spi_handle);
}
When I set sample rate to 125Hz, I can receive stable data from ads1292r without connecting to body. However, I can’t obtain stable data when I set sample rate to 250Hz, and the received data is misaligned and wrong. Here are the images of 125Hz and 250hz:
250Hz and unstable data
125Hz and stable data
I think this might be due to issues with FreeRTOS task scheduling,but I’m not certain and don’t know how to address this problem.I want to achieve to obtain right data at 250Hz.I would appreciate it if someone can give me some help!
WeiShx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.