using Arduino IDE SPI.h library with ESP32

wdouglas1999
Posts: 1
Joined: Fri Mar 10, 2017 10:17 pm

using Arduino IDE SPI.h library with ESP32

Postby wdouglas1999 » Sat Mar 11, 2017 12:54 am

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.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: using Arduino IDE SPI.h library with ESP32

Postby kolban » Sat Mar 11, 2017 5:44 am

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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

onehorse
Posts: 70
Joined: Mon Feb 15, 2016 1:35 am

Re: using Arduino IDE SPI.h library with ESP32

Postby onehorse » Sun Mar 12, 2017 1:21 am

I used the SPI.h library to read SPI flash with the Arduino IDE, you can see how here:

https://github.com/kriswiner/ESP32

bhavenm
Posts: 4
Joined: Sun Oct 08, 2017 5:03 pm

Re: using Arduino IDE SPI.h library with ESP32

Postby bhavenm » Fri Oct 27, 2017 8:37 am

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.

Monstercrunch
Posts: 3
Joined: Thu Aug 03, 2017 5:46 pm

Re: using Arduino IDE SPI.h library with ESP32

Postby Monstercrunch » Wed Dec 20, 2017 6:12 pm

Hi !

Any news here ? :)

Thanks

User avatar
ESP_krzychb
Posts: 400
Joined: Sat Oct 01, 2016 9:05 am
Contact:

Re: using Arduino IDE SPI.h library with ESP32

Postby ESP_krzychb » Thu Dec 21, 2017 2:15 pm

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.

akshu15
Posts: 3
Joined: Sun Aug 23, 2020 1:54 pm

Re: using Arduino IDE SPI.h library with ESP32

Postby akshu15 » Tue Aug 25, 2020 3:57 pm

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

ESP_Sara
Posts: 7
Joined: Thu Nov 05, 2020 9:45 am

Re: using Arduino IDE SPI.h library with ESP32

Postby ESP_Sara » Sat Nov 28, 2020 2:34 pm

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.

Who is online

Users browsing this forum: No registered users and 116 guests