Hi everyone,
I try to read data from an external ADC and send it via WiFi to my computer. Because of 16-bit resolution and 10 kHz sampling rate I get 1.6 Mbit/s of data to send.
The SPI reading happens in an ISR, which is always on core 1. For this reason, the sending task is a FreeRTOS task pinned to Core 0.
If I don't use SPI for data reading, the WiFi speed is sufficient. But when I use SPI, the WiFi speed slows down to about 0.8 Mbit/s and my queue runs over.
Is it possible that the SPI driver or any other background process slows core 0 down so much?
Or can I force the ISR to run on Core 0, so I can swap the tasks?
Thanks in advance!
Best regards!
WiFi getting slow if using SPI on other core
Re: WiFi getting slow if using SPI on other core
I would strongly recommend that you do NOT do anything like that in a ISR. SPI, depending on what method you use also uses interrupts.The SPI reading happens in an ISR
Maybe something along the lines of using xQueueSendFromISR() might be fast enough for you. Not sure...
If not then I would set a volatile variable true, in the ISR, and in another waiting task that is cecking for it to go true, will then read the A/D, and then set it false, and wait again.
Take a look at this GPIO example that uses it.
https://github.com/espressif/esp-idf/bl ... ple_main.c
I'd first try to use something like this
Code: Select all
static void gpio_task_example(void* arg)
{
uint32_t io_num;
for(;;) {
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
// Here is where you read your A/D
}
}
}
Re: WiFi getting slow if using SPI on other core
Hi username,
I implemented your suggestion in my Code now.
The WiFi is fast enough again. Thanks!
I did it with an integer Variable, which gets increased in the ISR and decreased in the SPI-read-task. Hope it won't have bad side effects.
But my code is still not working perfectly. Every time I send data over WiFi, the sampling is getting irregular and messing up my data. For example look at the picture were I try to read a 100 Hz sine signal. The sine looks good until a data package is sent (around data point 3000).
Do you know anything, to trigger the SPI-reading right when the interrupt happens? (Thought about Task Notifications, but got a code issue with it)
Thanks for your help!
I implemented your suggestion in my Code now.
The WiFi is fast enough again. Thanks!
I did it with an integer Variable, which gets increased in the ISR and decreased in the SPI-read-task. Hope it won't have bad side effects.
But my code is still not working perfectly. Every time I send data over WiFi, the sampling is getting irregular and messing up my data. For example look at the picture were I try to read a 100 Hz sine signal. The sine looks good until a data package is sent (around data point 3000).
Do you know anything, to trigger the SPI-reading right when the interrupt happens? (Thought about Task Notifications, but got a code issue with it)
Thanks for your help!
Re: WiFi getting slow if using SPI on other core
I solved the problem by myself now.
My loop() function was empty, but now I filled it with a delay. So it is "turned off" and the Core needs no resources for it.
My loop() function was empty, but now I filled it with a delay. So it is "turned off" and the Core needs no resources for it.
Who is online
Users browsing this forum: No registered users and 92 guests