SPI slave communication with another microcontroller

karimuk
Posts: 5
Joined: Wed May 31, 2017 7:58 am

SPI slave communication with another microcontroller

Postby karimuk » Wed May 31, 2017 8:01 am

Hi,
Anyone has an example code of SPI communication. The esp32 supposed to work as slave with an other microcontroller.
The esp32 has to receive some data (with interrupt or not) and respond.
Thanks you for your help.

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

Re: SPI slave communication with another microcontroller

Postby ESP_Sprite » Fri Jun 02, 2017 2:05 am

There is an example of two ESP32s communicating with eachother using SPI, one as a master, the other as a slave. You can find it in esp-idf under examples/peripherals/spi_slave.

karimuk
Posts: 5
Joined: Wed May 31, 2017 7:58 am

Re: SPI slave communication with another microcontroller

Postby karimuk » Fri Jun 02, 2017 12:51 pm

Thank you for your response, but i want the ESP32 wait for spi communication initiated by the master.
in the example code of spi communication between ESP32s in esp-idf, the function used is:
spi_slave_transmit(HSPI_HOST, &t, portMAX_DELAY); and this transmit data.

to simplify the flowchart of the example i am looking for is:

Start -> Idle -> if SPI interrupt -> Read spi data -> End


Thank you in advance for your help.
Attachments
spi.png
spi.png (12.76 KiB) Viewed 1381 times

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

Re: SPI slave communication with another microcontroller

Postby ESP_Sprite » Fri Jun 02, 2017 1:11 pm

Spi_transmit will actually block until the master has exchanged data with the slave. No need to mess around with interrupts specifically, the driver will take care of that.

karimuk
Posts: 5
Joined: Wed May 31, 2017 7:58 am

Re: SPI slave communication with another microcontroller

Postby karimuk » Fri Jun 02, 2017 1:42 pm

Ok thanks for your help

karimuk
Posts: 5
Joined: Wed May 31, 2017 7:58 am

Re: SPI slave communication with another microcontroller

Postby karimuk » Tue Jun 20, 2017 9:35 am

Hi,
I come back to you, about the spi transaction, My esp32 works as slave, I need SPI Read transaction that the slave begins transmitting data on the MISO After receiving a "read commad" as shown in the folowing figure:
thank you for your help.
Attachments
spi.png
spi.png (81.63 KiB) Viewed 1207 times

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

Re: SPI slave communication with another microcontroller

Postby ESP_Sprite » Tue Jun 20, 2017 10:03 am

That unfortunately is not possible using the current driver. The SPI slave interface does have another mode of operation which can use the mixed instruction/data concept that's shown in your picture (and the hardware for that is documented in the technical reference manual), but we do not have a driver for it. With the help of the technical reference manual, you should however be able to write your own.

karimuk
Posts: 5
Joined: Wed May 31, 2017 7:58 am

Re: SPI slave communication with another microcontroller

Postby karimuk » Tue Jun 20, 2017 12:06 pm

Ok thank you.

dipankarpanda
Posts: 4
Joined: Thu Nov 23, 2017 12:33 pm

Re: SPI slave communication with another microcontroller

Postby dipankarpanda » Mon Dec 11, 2017 12:06 pm

Hi,
I have the similar question like @karimuk.

I am trying to connect ESP32 as a SPI Slave mode with a sensor (the senor is not just a sensor, it is a sensor device, equipped microcontroller in it, which is the Master).

I want to enable the receive interrupt of SPI slave, so that, whenever any byte I receive from Sensor, control goes to receive ISR and do some task.

In the driver provided by esp-idf, I couldn't find the interrupt enable option and also interrupt handler/ISR.

From the application code it looks like we have call this function [b]

Code: Select all

spi_slave_transmit(HSPI_HOST, &t, portMAX_DELAY);
[/b] to send or receive anything through SPI. But I want to get an interrupt whenever ESP32 SPI slave receives some data.

So, kindly help me in finding, how I can enable the receive interrupt for SPI communication while it is in slave more. Any information will be highly appreciated.

Thanks
Dipankar

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

Re: SPI slave communication with another microcontroller

Postby ESP_Sprite » Tue Dec 12, 2017 12:31 am

Effectively, you don't. That call will not return until a transmission is done by the master. (Other tasks will run while the SPI interface is doing this.)

Who is online

Users browsing this forum: No registered users and 3 guests