Call SPI into timer ISR

AG1702
Posts: 11
Joined: Mon Feb 01, 2021 7:07 pm

Call SPI into timer ISR

Postby AG1702 » Thu Feb 04, 2021 2:26 am

I've got a problem similar to https://www.esp32.com/viewtopic.php?t=5240.

I need to send and receive information to an IC over SPI. This task has to be made with specific timing, hence I've got a time routine made with Timer 0 and interrupts.

The problem is when I write spi_device_transmit(spi, &t) (or something related to SPI) into the timer ISR function, the CPU crashes.

How can I solve this?

It is important to mention that I'm not using FreeRTOS and I'm not intended to use it. In the cited post there is a solution using FreeRTOS, but how can I solve this problem without FreeRTOS?

Regards.
Alejandro.

ESP_Sprite
Posts: 9592
Joined: Thu Nov 26, 2015 4:08 am

Re: Call SPI into timer ISR

Postby ESP_Sprite » Thu Feb 04, 2021 3:25 am

AG1702 wrote:
Thu Feb 04, 2021 2:26 am
It is important to mention that I'm not using FreeRTOS and I'm not intended to use it. In the cited post there is a solution using FreeRTOS, but how can I solve this problem without FreeRTOS?

...You *are* using FreeRTOS. You may not be calling into any FreeRTOS functions yourself, but everything around it (the timer API, the SPI API, WiFi etc) is using FreeRTOS, so you're still bound to its limitations and need to find solutions in the feature it offers.

AG1702
Posts: 11
Joined: Mon Feb 01, 2021 7:07 pm

Re: Call SPI into timer ISR

Postby AG1702 » Thu Feb 04, 2021 4:48 am

Thanks for the reply.

So what could be a possible solution, please. With example code would be great.

ESP_Sprite
Posts: 9592
Joined: Thu Nov 26, 2015 4:08 am

Re: Call SPI into timer ISR

Postby ESP_Sprite » Thu Feb 04, 2021 5:36 am

See the answer I gave in that topic: set a semaphore in your ISR, have a task running that waits for that semaphore to be set and runs the SPI transaction afterwards.

AG1702
Posts: 11
Joined: Mon Feb 01, 2021 7:07 pm

Re: Call SPI into timer ISR

Postby AG1702 » Thu Feb 04, 2021 11:35 pm

spi_device_handle_t spi; and spi_transaction_t t; should be declared as global in order to be used from all of the task?

ESP_Sprite
Posts: 9592
Joined: Thu Nov 26, 2015 4:08 am

Re: Call SPI into timer ISR

Postby ESP_Sprite » Fri Feb 05, 2021 8:10 am

That very much depends on what you're trying to code.

Who is online

Users browsing this forum: Bing [Bot], irahul and 102 guests