The PCBs haven’t arrived yet. So, I worked on the test code for the SPI ram.
Using the datasheet, I started setting up for SPI overlap mode. On the ESP8266 there are two hardware SPI modules. In overlap mode, they share the same pins. This means that if you use the second SPI module you can directly work with the flash memory by using CS0 for the chip select. I don’t see a lot of use for that other than for performance. If you choose a different chip select, like I am using GPIO15. You are just sharing the pins with the processor. You have to make sure your code will run in RAM while using the second SPI. ESP8266 documentation calls the second SPI HSPI.
From Microchips 23LC1024 datasheet, the sequence to write to the SPI RAM in sequential mode is:
Set CS low, write out the value 2 MSB First followed by the 24bit address to start writing at(in 3 bytes), followed by the data to be written(as many bytes as wanted up to the size of the RAM) followed by setting CS high.
A Sequential read has the following steps:
Set CS low, Write out the value 3 MSB first followed by the 24 bit address, then read in as many bytes as wanted. Then set CS high.
Side Note: MSB means Most Significant Bit. Some protocols transfer in the opposite order or LSB first. It is important to know this when setting up any serial communication. Data is clocked out on the falling edge of SCK and latched on the rising edge of SCK. The inactive state of SCK is low.
To help out Espressif provides a guide called:
ESP8266 SPI Overlap & Display Application Guid
This guide describes the SPI Overlap mode API as well as gives a reference implementation using an LCD. Unfortunately this document is missing a lot of useful information. There is a post on Espressif’s forum describing it and showing an example.
To get started I have created two new files SPIRam.c and SPIRam.h. This will make the code easier to locate and modify. To begin with I just want to write some data, and read it back and send it out on the serial connection. Basically a Hello World on the SPI RAM
I created 3 functions:
initSpiRam(); // Set up SPI and Overlap Mode
disableSpiRam(); // Shut down Overlap Mode
writeRam(char data[], int length);
readRam(char data[], int length);
I got it to build but I am unable to test it.
I still have to add a couple of commands over the serial port to tell it to write and tell it to read. I pushed a copy up to Github
I’d like to hear about the projects you are working on. Please leave a comment below.