Page 1 of 1

SPI slave communication with another microcontroller

Posted: Wed May 31, 2017 8:01 am
by karimuk
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.

Re: SPI slave communication with another microcontroller

Posted: Fri Jun 02, 2017 2:05 am
by ESP_Sprite
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.

Re: SPI slave communication with another microcontroller

Posted: Fri Jun 02, 2017 12:51 pm
by karimuk
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.

Re: SPI slave communication with another microcontroller

Posted: Fri Jun 02, 2017 1:11 pm
by ESP_Sprite
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.

Re: SPI slave communication with another microcontroller

Posted: Fri Jun 02, 2017 1:42 pm
by karimuk
Ok thanks for your help

Re: SPI slave communication with another microcontroller

Posted: Tue Jun 20, 2017 9:35 am
by karimuk
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.

Re: SPI slave communication with another microcontroller

Posted: Tue Jun 20, 2017 10:03 am
by ESP_Sprite
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.

Re: SPI slave communication with another microcontroller

Posted: Tue Jun 20, 2017 12:06 pm
by karimuk
Ok thank you.

Re: SPI slave communication with another microcontroller

Posted: Mon Dec 11, 2017 12:06 pm
by dipankarpanda
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

Code: Select all

spi_slave_transmit(HSPI_HOST, &t, portMAX_DELAY);
[/b][/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

Re: SPI slave communication with another microcontroller

Posted: Tue Dec 12, 2017 12:31 am
by ESP_Sprite
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.)