Closed Rickxiaoxin closed 2 weeks ago
It's most likely a printf issue. What happens if you change printf to ESP_LOGx?
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]);
for (int i = 0; i < 9; i++)
{
val[i] = ads1292r_receive_data(spi_handle);
}
Seems you using SPI read only 1 byte for 1 transaction, ,,there may some order issue, this chip should support read 1 pack(9 bytes) in one transaction, that should more stable.
And then, what the convention resolution you set for 250Hz, different resolution need different time to finish convention.
And SPI transaction also need time, refer to your datasheet bellow, you can also increase your SPI bus frequency.
It's most likely a printf issue. What happens if you change printf to ESP_LOGx?
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]);
@nopnop2002 I'm very sorry for the late response. I feel that the issue may lie in SPI communication. Currently, I'm using polling instead of interrupts for SPI communication and have lowered the sampling rate to ensure receiving correct information.I will try the method you mentioned and will reply later with the results.
for (int i = 0; i < 9; i++) { val[i] = ads1292r_receive_data(spi_handle); }
Seems you using SPI read only 1 byte for 1 transaction, ,,there may some order issue, this chip should support read 1 pack(9 bytes) in one transaction, that should more stable.
And then, what the convention resolution you set for 250Hz, different resolution need different time to finish convention.
And SPI transaction also need time, refer to your datasheet bellow, you can also increase your SPI bus frequency.
@wanckl I'm very sorry for the late response.I previously used the same settings in STM32, and I could receive correct information. Initially, I was communicating by receiving 9 bytes at once, which also encountered the aforementioned issue. Later, I changed it to receive one byte at a time. The problem was resolved after I disabled the task watchdog and interrupt watchdog, and set FreeRTOS config tick=100 to 1000. However, I'm not sure why this resolved the issue.
I disabled the task watchdog and interrupt watchdog
usleep(10000) and vTaskDelay(1) both wait 10ms, but using usleep will cause a TaskWatchDog alert regardless of the wait time.
// TaskWatchDog alerts are not fired.
while(1) {
vTaskDelay(1); // wait for 10mSec
}
// TaskWatchDog alerts are fired.
while(1) {
usleep(10000); // wait for 10mSec
}
If you use usleep, you must disable task watchdog. If you disable TaskWatchDog, there is no need to wait at all.
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);
}
}
}
I disabled the task watchdog and interrupt watchdog
usleep(10000) and vTaskDelay(1) both wait 10ms, but using usleep will cause a TaskWatchDog alert regardless of the wait time.
// TaskWatchDog alerts are not fired. while(1) { vTaskDelay(1); // wait for 10mSec }
// TaskWatchDog alerts are fired. while(1) { usleep(10000); // wait for 10mSec }
If you use usleep, you must disable task watchdog. If you disable TaskWatchDog, there is no need to wait at all.
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); } } }
@nopnop2002 Thank you very much. Now I know function usleep will trigger the task watchdog, I will try it!
Now I know function usleep will trigger the task watchdog
To be precise, usleep() cannot avoid TaskWatchDog alerts.
Now I know function usleep will trigger the task watchdog
To be precise, usleep() cannot avoid TaskWatchDog alerts.
So only the vTaskDelay() function can avoid TaskWatchDog alerts?
So only the vTaskDelay() function can avoid TaskWatchDog alerts?
Yes. You are right.
I think esp_task_wdt_reset() can also avoid TaskWatchDog alerts.
Answers checklist.
IDF version.
5.2.1
Espressif SoC revision.
ESP32-C6
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
PowerShell
Development Kit.
ESP32-C6-DevKitC-1
Power Supply used.
USB
What is the expected behavior?
can obtain stable data like this
What is the actual behavior?
can't obtain stable data
Steps to reproduce.
this is my code.
Debug Logs.
More Information.
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 use gpio interrupt to send queue, and create task to receive queue, then receive data from ads1292r. 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. 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 .I would appreciate it if someone could give me some help!