Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By metalphreak
#14909 I've got plans to eventually write in "software" chip select support at some point. Basically tell it which GPIO pin you want to use instead of the hardware assigned one. This way multiple SPI slave devices can share the HSPI bus.

Will be used something like:

spi_transaction(HSPI_CS0, param1, param2)

and it changes the HSPI CS pin (GPIO15) to a GPIO set to high temporarily, while it toggles the GPIO0 (HSPI_CS0) pin as a chip select.

Then I can also use that software CS pin in the inverted mode (for devices that are active high CS).

Also, when sending/receiving data, it's only using SPI_W0 register for now. Will add some code later to allow for the SPI_USR_MOSI_HIGHPART and SPI_USR_MISO_HIGHPART configurations where it uses SPI_W8 instead.

Eventually going to expand it with another function, where you pass it a pointer to an array of data, and it sends the whole lot in one command. There are 16 SPI_Wx registers holding a total of 64 bytes. While it's sending those 64bytes you can return to usercode and do more stuff while it runs in the background (which is the entire advantage of using hardware SPI!).
However, nothing stopping the code from loading up another 64bytes straight after the transmission completes ;)

I'll be writing some other libraries soon, that build off this SPI driver as a module. SSD1306 OLED display is next on my list. Software i2c is just too slow at updating a 128x64 display and it holds up any other code from executing.
User avatar
By hcoskun
#14979 Hi Metalphreak,

Thanks for your work.

I try to make the ESP8266 talk to an nRF24L01+ through SPI. Unfortunately, it does not work yet. My code works fine with the Arduino UNO/NANO. The first attempt was to use the new Arduino IDE for the ESP8266. Compilation and Upload worked fine but the nRF24L01+ was not sending anything. I hooked up a logic analyzer to compare the signals coming from the Arduino and the ESP8266. But it looked completely different. :x

Before diving into the SPI library I want to try your code, whats the best way to start. Do you plan to integrate it into any project like Arduino IDE or nodemcu ? A small project showing the basics would be nice for interested developers.

Regards
User avatar
By metalphreak
#15007 No plans to rewrite this code into nodemcu or Arduino IDE from me as I prefer to write code natively.

The maintainers of those packages are more than welcome to use my code to add more SPI functionality to them if they want though.

The nRF24L01+ is not an easy one to start with, since you basically need to either write an entire driver for it with the various commands, or port an existing library to the ESP8266.

I've written a quick bit of code for using microwire eeproms which is up on github: https://github.com/MetalPhreak/ESP8266_Microwire_EEPROM

I haven't had a chance to test it yet, but it's the same basic commands I was using when testing. It might give you an idea of how I'm using the cmd and address functions. The instruction set given on page 11 onwards in the datasheet is pretty basic. Should be pretty easy to compare those with the code to see how it's done. I'll be documenting the code later.

http://www.st.com/web/en/resource/technical/document/datasheet/CD00001142.pdf

It's the only device I have handy at the moment that will send back data to the ESP8266. Waiting on some SSOP breakout boards to arrive so I can start testing with the NXP PCA9685 LED controller :)