WiFi getting slow if using SPI on other core

linearo
Posts: 6
Joined: Sun Nov 03, 2019 1:29 pm

WiFi getting slow if using SPI on other core

Postby linearo » Sat Feb 01, 2020 1:48 pm

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!

username
Posts: 533
Joined: Thu May 03, 2018 1:18 pm

Re: WiFi getting slow if using SPI on other core

Postby username » Sat Feb 01, 2020 9:23 pm

The SPI reading happens in an ISR
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.

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
        }
    }
}

linearo
Posts: 6
Joined: Sun Nov 03, 2019 1:29 pm

Re: WiFi getting slow if using SPI on other core

Postby linearo » Tue Feb 04, 2020 4:44 pm

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!
ReadSPI0_Zoom.jpg
incorrect data samling rate while using WiFi
ReadSPI0_Zoom.jpg (172.11 KiB) Viewed 4899 times

linearo
Posts: 6
Joined: Sun Nov 03, 2019 1:29 pm

Re: WiFi getting slow if using SPI on other core

Postby linearo » Sun Feb 16, 2020 2:36 pm

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.

Who is online

Users browsing this forum: No registered users and 84 guests