Page 1 of 1

using Arduino IDE SPI.h library with ESP32

Posted: Sat Mar 11, 2017 12:54 am
by wdouglas1999
Good Day all.
I am starting my journey with the ESP32 on the Adruino IDE platform and i would like to know if anyone could clarify things for me.
I've purchase the book Kolban's book on ESP 32 and found it very interesting, however i would have appreciated more examples explaining code syntax.

Anyways, the questions i have are:

1) Can the SPI.h library be used with the esp32? I have tried countless times but cannot seem to get in working. I've used it with the Esp 8266 with no problems.
2) I found the esp32-hal-spi.h library and followed Kolban's book to transfer a few bytes, now i can see the HSPI bus is active with an oscilloscope ,but the actual data received is either all zeros or garbage. I'm certain i'm not understanding how the actual instruction is working.
Basically i need to implement this line of code,
uint8_t tmp = SPI.transfer(0);
which is from the SPI library

How would i do this using the esp32-hal-spi.h libray. Is there an equivalent?
How would i write this line for the ESP 32 in Arduino IDE?

I would really appreciate any assistance. Im sure by now it is evident that i am not a seasoned programmer ,but i do enjoy making things with these chips.
Thank you in advance.

Re: using Arduino IDE SPI.h library with ESP32

Posted: Sat Mar 11, 2017 5:44 am
by kolban
Howdy,
I think the assumption with the Arduino library would be to use Arduino APIs. For example, the Arduino SPI library found here:

https://www.arduino.cc/en/reference/SPI

The principle should be that you take an Arduino sketch that drives SPI and it should compile cleanly and run on the ESP32. For me, I normally plug in a logic analyzer and capture a trace of the transmissions. Many of the logic analyzer software packages can then interpret the logic signals as SPI and decode them to validate that what was actually sent on the wires was what was expected.

Re: using Arduino IDE SPI.h library with ESP32

Posted: Sun Mar 12, 2017 1:21 am
by onehorse
I used the SPI.h library to read SPI flash with the Arduino IDE, you can see how here:

https://github.com/kriswiner/ESP32

Re: using Arduino IDE SPI.h library with ESP32

Posted: Fri Oct 27, 2017 8:37 am
by bhavenm
I am using the esp 32 to interface with the LIS2HH12(accelerameter from ST Microelectronics.). I am using 18 for clock, 23 is MOSI, 19 is MISO and 5 for chip select.

I wrote a simple code to read the WHO_AM_I register. Accelerometer generates the necessary. Expec t ed output as required for this register. I saw the waveforms on oscilloscope. However when I connect the SDO pin to MISO, the signals disappear. Esp32 also reads 0.

I am wondering if there is any changes required for the pin 19 which is the pin involves. The layout on the Geek creit board seems ok as I can blink an LED on pin 19.

Do I need to have a pull up or pull down resistor? Or any other resistor for impedance matching?

Any inputs here will be very helpful. My whole project is at halt for the past 4 days.

Thanks,
Bhaven.

Re: using Arduino IDE SPI.h library with ESP32

Posted: Wed Dec 20, 2017 6:12 pm
by Monstercrunch
Hi !

Any news here ? :)

Thanks

Re: using Arduino IDE SPI.h library with ESP32

Posted: Thu Dec 21, 2017 2:15 pm
by ESP_krzychb
Hi Monstercrunch,
onehorse wrote: I saw the waveforms on oscilloscope. However when I connect the SDO pin to MISO, the signals disappear. Esp32 also reads 0.
Do you mean that the signal line goes to zero as seen on the scope after you connect the SDO pin to MISO? Or the signal is correct on the scope but you read zero in your code?

Have you tried using another pin for MISO?
bhavenm wrote:Do I need to have a pull up or pull down resistor? Or any other resistor for impedance matching?
FWIW, I have been recently writing an ESP-IDF component for LIS35DE that looks like a similar chip by ST.
On the breadboard I have, the SDO pin does not have any pullup, unlike the other SPI signal pins. I have been using exactly GPIO19 for MISO / SDO and did not see any issues.

Re: using Arduino IDE SPI.h library with ESP32

Posted: Tue Aug 25, 2020 3:57 pm
by akshu15
Hi team,

Using SPI.h library in arduino IDE can you guide me on how to read data from slave devices?

Anyone has experience about it. Can someone help me?

Thanks,
Akshay Godase

Re: using Arduino IDE SPI.h library with ESP32

Posted: Sat Nov 28, 2020 2:34 pm
by ESP_Sara
Hi akshu15,

I'll let here a link to a code that shows how to use SPI.h from the arduino IDE.
In this code is shown also how to remap the MISO, MOSI and SCLK buses to other pins.
One important point:
Observe that when initialing the SPI instance, only MOSI, MISO and SCLK are passed as parameters to the SPI driver.
The CS is controlled by the external peripheral driver, in this case the LoRa driver.
It's a good practice, mainly when you are developing an application that uses multiple peripherals in an SPI.

https://github.com/majuzabbal/LoRaENELT ... ender1.ino

Take a look at this example and you will be able to know how to use SPI.h from arduino IDE.

If you have doubts regarding the steps to read from slave devices, I recommend you to look inside the LoRa driver itself.
It will use the SPI API and control de CS pin to enable and disable communication to that slave device.

But if you have problems, post it here.