ESP32 vs ESP8266 spi differences

Duhjoker
Posts: 85
Joined: Mon Mar 20, 2017 8:09 am

ESP32 vs ESP8266 spi differences

Postby Duhjoker » Fri Apr 07, 2017 10:02 pm

Hi guys

I'm trying to update my ili9341 TFT library to be compatible with the new ESP32. The library I'm using has the proper stuff need to use an ESP8266. So what I'm wondering is if the 8266's and 32's are spi compatible. Do I need to worry about writing some new code that I wouldn't know how to begin with or can I add the ESP32 to the defines and ifs and else if's that already exist for the esp8266.
Attachments
TFT_ILI93XX-master2.0.zip
(235.24 KiB) Downloaded 611 times
Fear is the mind killer.......

GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP

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

Re: ESP32 vs ESP8266 spi differences

Postby kolban » Fri Apr 07, 2017 11:29 pm

The APIs for SPI and I2C are very different between the ESP8266 and ESP32. You will likely have to port your current project to use the new ESP32 APIs.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Duhjoker
Posts: 85
Joined: Mon Mar 20, 2017 8:09 am

Re: ESP32 vs ESP8266 spi differences

Postby Duhjoker » Sat Apr 08, 2017 12:20 am

I found this...........

https://github.com/MartyMacGyver/ESP32_Adafruit_ILI9341

Maybe I can use it update my library.
Fear is the mind killer.......

GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP

Duhjoker
Posts: 85
Joined: Mon Mar 20, 2017 8:09 am

Re: ESP32 vs ESP8266 spi differences

Postby Duhjoker » Wed Apr 12, 2017 2:57 am

Ok so after finding the Adafruit drivers for the ili9341 TFT with added ESP32 support and creating an all in one graphics library, I realized I still need a couple functions. Like........

Clear memory
Update screen
Update all

And some frame buffer stuff. Things needed for a gaming library so buttons and TFT and sound and ETC and the buffer to help make every thing solid and not flashy. I do have a library with all these things in it but it's not ESP32 compatible. It is ESP8266 compatible though.

The SPI stuff is the only thing holding back my library with working with the ESP32. So now I'm curious.

I've got my computer open with visual studio looking at both SPI files from the esp8266 and the esp32 plus the hal_spi from the esp32 includes.

The only differences I really see is that the esp32 version has some functions the other doesn't and vice versa. Other than that every thing else matches up. Except for _bitorder(lsbfirst) on the 8266 and msbfirst on the 32.

Looks like I can update the esp32 spi file to include the proper functions or what ever from the ESP8266 spi.

Edit::

ok the esp32 doesn't need the commands from the 8266. Still they use the same command functions but with different integers in the parameters. I know the internal structure of the cpp might be different but I don't see why I can't update the spi bits in my code that use esp8266 to also include esp32.

I also found this........

https://github.com/Ebiroll/qemu-xtensa- ... mebuffer.c

But I cant figure out if I can use it with the arduino IDE or some other way after reading the front page for the library
Fear is the mind killer.......

GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP

Duhjoker
Posts: 85
Joined: Mon Mar 20, 2017 8:09 am

Re: ESP32 vs ESP8266 spi differences

Postby Duhjoker » Sun Apr 16, 2017 9:06 am

Can i get some feed back on the differences please. Hopefully with an explanation and a some advice?

I keep loooking at the spi for both the ESP8266 and 32 and cant find any thing different except esp32 divides its functions into two sets of files. But they connect. Also it uses lsb first over msbfirst.

Also adafruit uses the same spi functions for both mcu's

Ok thank you for your help
Fear is the mind killer.......

GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: ESP32 vs ESP8266 spi differences

Postby ESP_igrr » Sun Apr 16, 2017 9:30 am

Could you please clarify which "files" you are referring to? ESP-IDF register header files (inside soc directory)? ESP-IDF spi_master driver? Arduino SPI HAL? Arduino SPI library?

The peripherals do have many things in common, so basic usage with FIFO in master mode can be implemented the same way, subject to renaming of some registers. For the ESP32, you can get register descriptions from the ESP32 technical reference manual.

Duhjoker
Posts: 85
Joined: Mon Mar 20, 2017 8:09 am

Re: ESP32 vs ESP8266 spi differences

Postby Duhjoker » Mon Apr 17, 2017 3:23 am

the files I am talking about are the esp32 and esp8266 SPI library .h an.cpp in the arduino esp32 library and esp8266 library.

ok so heres the esp32

Code: Select all

#ifndef _SPI_H_INCLUDED
#define _SPI_H_INCLUDED

#include <stdlib.h>
#include "pins_arduino.h"
#include "esp32-hal-spi.h"

class SPISettings
{
public:
    SPISettings() :_clock(1000000), _bitOrder(SPI_MSBFIRST), _dataMode(SPI_MODE0) {}
    SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) :_clock(clock), _bitOrder(bitOrder), _dataMode(dataMode) {}
    uint32_t _clock;
    uint8_t  _bitOrder;
    uint8_t  _dataMode;
};

class SPIClass
{
private:
    int8_t _spi_num;
    spi_t * _spi;
    bool _use_hw_ss;
    int8_t _sck;
    int8_t _miso;
    int8_t _mosi;
    int8_t _ss;
    uint32_t _div;
    uint32_t _freq;
	bool useHwCs;//duhjoker
//	inline void setDataBits(uint16_t bits);
    bool _inTransaction;
//	inline void setDataBits(uint16_t bits);
    void writePattern_(uint8_t * data, uint8_t size, uint8_t repeat);
//	void writeBytes_(uint8_t * data, uint8_t size);

public:
    SPIClass(uint8_t spi_bus=HSPI);
    void begin(int8_t sck=SCK, int8_t miso=MISO, int8_t mosi=MOSI, int8_t ss=-1);
    void end();

    void setHwCs(bool use);
    void setBitOrder(uint8_t bitOrder);
    void setDataMode(uint8_t dataMode);
    void setFrequency(uint32_t freq);
    void setClockDivider(uint32_t clockDiv);

    void beginTransaction(SPISettings settings);
    void endTransaction(void);

    uint8_t transfer(uint8_t data);
    uint16_t transfer16(uint16_t data);
    uint32_t transfer32(uint32_t data);
    void transferBytes(uint8_t * data, uint8_t * out, uint32_t size);
    void transferBits(uint32_t data, uint32_t * out, uint8_t bits);

    void write(uint8_t data);
    void write16(uint16_t data);
//	void write16(uint16_t data, bool msb);
    void write32(uint32_t data);
//	void write32(uint32_t data, bool msb);
    void writeBytes(uint8_t * data, uint32_t size);
    void writePixels(const void * data, uint32_t size);//ili9341 compatible
    void writePattern(uint8_t * data, uint8_t size, uint32_t repeat);

    spi_t * bus(){ return _spi; }
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPI)
extern SPIClass SPI;
#endif

//extern SPIClass SPI;

#endif
now I tried to add set data bits from the esp8266 as you can see but when I try to compile I get these errors..

Code: Select all

Arduino: 1.8.0 (Windows 7), TD: 1.34, Board: "ESP32 Dev Module, 80MHz, 921600, None"

C:\Users\duhjoker\Documents\Arduino\hardware\espressif\esp32\libraries\SPI\src\SPI.cpp: In member function 'void SPIClass::setDataBits(uint16_t)':

C:\Users\duhjoker\Documents\Arduino\hardware\espressif\esp32\libraries\SPI\src\SPI.cpp:199:27: error: 'SPIMMOSI' was not declared in this scope

  const uint32_t mask = ~((SPIMMOSI << SPILMOSI) | (SPIMMISO << SPILMISO));

                           ^

C:\Users\duhjoker\Documents\Arduino\hardware\espressif\esp32\libraries\SPI\src\SPI.cpp:199:39: error: 'SPILMOSI' was not declared in this scope

  const uint32_t mask = ~((SPIMMOSI << SPILMOSI) | (SPIMMISO << SPILMISO));

                                       ^

C:\Users\duhjoker\Documents\Arduino\hardware\espressif\esp32\libraries\SPI\src\SPI.cpp:199:52: error: 'SPIMMISO' was not declared in this scope

  const uint32_t mask = ~((SPIMMOSI << SPILMOSI) | (SPIMMISO << SPILMISO));

                                                    ^

C:\Users\duhjoker\Documents\Arduino\hardware\espressif\esp32\libraries\SPI\src\SPI.cpp:199:64: error: 'SPILMISO' was not declared in this scope

  const uint32_t mask = ~((SPIMMOSI << SPILMOSI) | (SPIMMISO << SPILMISO));

                                                                ^

C:\Users\duhjoker\Documents\Arduino\hardware\espressif\esp32\libraries\SPI\src\SPI.cpp:201:2: error: 'SPI1U1' was not declared in this scope

  SPI1U1 = ((SPI1U1 & mask) | ((bits << SPILMOSI) | (bits << SPILMISO)));

  ^

exit status 1
Error compiling for board ESP32 Dev Module.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I cant seem to find those missing declarations. in the attachments is the library im trying to update to esp32
Grafx_esp32.zip
(234.79 KiB) Downloaded 588 times
Fear is the mind killer.......

GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: ESP32 vs ESP8266 spi differences

Postby ESP_igrr » Mon Apr 17, 2017 3:17 pm

Okay, so the register sets are similar, but the register *names* used in the ESP8266 Arduino core are not compatible with the ESP32.

ESP8266 Arduino core uses register names defined here: https://github.com/esp8266/Arduino/blob ... 266_peri.h

Note that these names are different from the official ESP8266 header files which come with the SDK, such as this one:
https://github.com/espressif/ESP8266_RT ... register.h

Register names used in the ESP32 SDK and the ESP32 Arduino core are defined here:
https://github.com/espressif/esp-idf/bl ... /spi_reg.h

Note that these names are similar to the ones used by the ESP8266 SDK (but not by the ESP8266 Arduino core).

Who is online

Users browsing this forum: Bing [Bot], Rckyan and 186 guests