Updating SPIN to work with ESP.

Status
Not open for further replies.
The Test program that had it, has a bunch of other stuff testing SPI speed using modified SPI libraries...

But: here is the above simply wrapped into simple program:
Code:
void setup() {
  while (!Serial && millis() < 4000) ;

  Serial.begin (115200);
  delay(250);
   Serial.println("Start");
  Serial.println(SCK, DEC);
  Serial.println(MISO, DEC);
  Serial.println(MOSI, DEC);
  Serial.println(SS, DEC);
}
void loop() {
  delay(250);
}

Output in debug terminal:
Code:
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0x00
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0008,len:8
load:0x3fff0010,len:2036
load:0x40078000,len:9988
load:0x40080000,len:252
entry 0x40080034
Start
18
19
23
5
These defines were on my system... Not sure if they will be defined on yours?
 
Should mention, with my ili9341_t3 ported to ESP, the frame buffer is somewhat working, however all of the colors are wrong. In particular I believe the memory works different.

I hacked up the fillScreen function to reverse the bytes and then I got the right output. So couple of options, could go through code and when I set the data into frame buffer memory, I could reverse the bytes. Or my function that draws the data out of the frame buffer could swap the bytes into some temporary buffer that I output to screen...

But for now may punt as not sure what I will use the ESP32 for...
 
Lol build a game console!

Ive been working on getting my tft to my esp32 but i cant find a pin out for SPI. The board i have is the EZSBC version.

Ive got

Mosi--------sd_data1
Miso--------sd_data0
Sck---------clk pin
CS----------cmd pin

But no DC pin
 
Last edited:
Yep as Michael said, you can use any IO pin for DC and most likely CS pin. At least as with my code there is not any support to have the hardware do it automatically for you...
 
In case anyone is interested. I thought I would upload a version of the hacked up library I was playing with for the ILI9341 that I was testing stuff out on ESP32. Also in the zip file is the test program.

The test program is buggy and not everything is fully working. But if you hit CR in terminal monitor it will alternate between doing the drawing of a test screen using primitives and doing it using the Frame buffer.

As mentioned before the code could not allocate the FB in one memory chunk so it is using two. Code has to detect when going across the boundary. Also the memory byte order is different so I think I have most all of the code mucked up to swap the order of bytes when I push them to the frame buffer.

I do not have the readPixel/Rect code implemented yet (if ever). Again not sure if I will take this any farther here.
 

Attachments

  • ili9341_esp.zip
    919.6 KB · Views: 71
Awesome thanks!!!!! For everything!!!!!

On the two part buffer...... Wouldn't it be easier to use both cores? Seems like you could set one to handle the buffer while the other processes program data.

Ok I have never had to name pin outs before. I always just used the pjrc stores pinout that's listed with the ili9341 TFT in store.

Where do I mark the pins in the code?

Edit::::: ok I think I get it. I name my DC and CS pins in my sketch. Like...

Grafx TFT - (cs_pin X , dc_pin Y) or something like that I'm not on my computer yet. Mosi and miso will always be mosi and miso.

Check this out particularly the readme........

https://github.com/elFallino/ILI9341_ESP32
 
Last edited:
Sorry I only know enough about these chips to try a few things and mostly by trial and error.

For my Test I was using the adafruit version of the display, as to not have to worry about wiring in the reset pin or use resistor for backlight...

Also I used their Arduino setup... It looks like they have other setups who may work differently.

Pin Names? Arduino works with pin numbers. As I mentioned before I found out the pin numbers for SPI by that simple program earlier.
I then used those in my program to pass off to the library. Should mention I ignore the passed in MISO/MOSI/SCK pins and use whatever pins SPI object uses.

And Again other ways to figure out what pins do what? Do a google search on things like: "esp-wroom-32 pinout"
You find things like links to: https://espressif.com/sites/default/files/documentation/esp32_pinout_v1_0.pdf

Which may or may not apply:

Likewise the Sparkfun page shows similar stuff: https://learn.sparkfun.com/tutorial....1488668613#installing-the-esp32-arduino-core


So you go to where you installed the ESP32 installation, in my case it is in <sketch folder>/hardware/espressif/esp32 and look at the file
boards.txt... In my case I am using the "ESP32 Dev Module", it says that is variant=esp32.

From there you look in the variants directory and you find the file pins_arduino.h. In here is lots of interesting information like:
Code:
static const uint8_t TX = 1;
static const uint8_t RX = 3;

static const uint8_t SDA = 21;
static const uint8_t SCL = 22;

static const uint8_t SS    = 5;
static const uint8_t MOSI  = 23;
static const uint8_t MISO  = 19;
static const uint8_t SCK   = 18;
...

And again I don't see if there are any board types defined specific for your board. So are you using the same one? If so the same pins should work. If not look at the appropriate section in the boards.txt to find which variant it is using and then look at its pin definitions.
 
Last edited:
Awesome thanks!!!!! For everything!!!!!

On the two part buffer...... Wouldn't it be easier to use both cores? Seems like you could set one to handle the buffer while the other processes program data.

Ok I have never had to name pin outs before. I always just used the pjrc stores pinout that's listed with the ili9341 TFT in store.

Where do I mark the pins in the code?

Edit::::: ok I think I get it. I name my DC and CS pins in my sketch. Like...

Grafx TFT - (cs_pin X , dc_pin Y) or something like that I'm not on my computer yet. Mosi and miso will always be mosi and miso.

Check this out particularly the readme........

https://github.com/elFallino/ILI9341_ESP32

FYI - updated the graphic test program to run... to get the numbers...
Code:
ILI9341 Test!
After TFT Begin
Display Power Mode: 0xCE
MADCTL Mode: 0x24
Pixel Format: 0x2
Image Format: 0x0
Self Diagnostic: 0xE0
Benchmark                Time (microseconds)
Screen fill              640012
Text                     41547
Lines                    185713
Horiz/Vert Lines         52787
Rectangles (outline)     33697
Rectangles (filled)      1318788
Circles (filled)         235510
Circles (outline)        237557
Triangles (outline)      44782
Triangles (filled)       455213
Rounded rects (outline)  94563
Rounded rects (filled)   1450594
Hit key to continue
So it is not doing too bad...
 
ok so I tried the lil program and it worked but no pinout. I've also extensively searched the board (EZSBC) but it is brand spankin new and doesn't have much documentation but the schematic and this one was a lil help. I asked Ddebeer who has been of some help gave me the pinout above but like this.....

Gpio 8: Mosi (SD_DATA1, spid, HS1_DATA1)

Gpio 7: miso (SD_DATA0, spiq, hs_1_data0) etc....

But the board doesn't have these numbers listed on it but I was able to use the schematic and find those.

But after looking at the board a lil closer I can see that it does have the PIN numbers you listed above.

I had no idea I could do that with the boards on the IDE thank you I will check that as well.

EDIT:::: I was actually talking about the 64bit data transfer on the link
 
Last edited:
Ok i would like to play around with the different libraries so I wondering if you might have an updatescreen() function that doesn't use the frame buffer? I have yours and the original Gamebuino function but it uses Nokia 5110 and the PCD stuff.

I also want to use it for the game controls. I have an update function that updates the music, the buttons and etc 20X a second and I would like to see what the differences are when changing the bitmap on command.
 
Sorry,

As I mentioned this is about as far as I will take this code. If I come up with some reason to want to actually use the ESP32 for something, than maybe I will take it a little farther.

But, I would then take the conversation to a forum more appropriate for the board. As this have very little to do with PJRC products...

And personally I enjoy working with the Teensy processors... Also with this display I doubt you will ever get to the same speed (or even near) as the Teensy 3.x code version, unless maybe you were able to convert the code to use DMA... And then I am still not sure as due to handling of CS pins.

The updateScreen function is there, but if you don't have a frame buffer it does not do anything... What would you expect it to do?

It is also hard for me to understand what you have actually tried out and what is working and what is not. For example it sounded like you had a display working on the ESP32 and maybe tried out a couple of different drivers. But then it now sounds like you still don't know which pins are the SPI pins???

So if it were me wanting to do a project like this with a board like this that I did not find a lot of specific information for. I would do things like:

First start with baby steps to try to understand the processor. - With all Arduino setups, I usually have an editor window (currently Sublime text) where I browse the files I mentioned like boards.txt, variants, pin tables...

A) try out the GPIO pins. Can I run some form of BLINK program? I don't believe my board has an LED on it, so I would try hooking up to Logic Analyzer (would not leave home without one). I did not do this with this one, but with other boards ran simple program that allowed me to type in pin number to start blinking and if it was not the LED pin, it would turn the LED pin to input... This allowed me to then jumper each of these pins to the LED pin, which would blink if the other IO pin was working properly... This also verifies that the USB serial port is working... Where you will find on this board you need to specify the correct Baud rate...

B) SPI - If I am going to use SPI - I often start off doing a couple of things: Look at the processor documents (Chapter 5 in this case), It mentions there are maybe 4 SPI buses... I then look at the SPI library code - Again this is installed as part of your install:
I take a quick look at the library code, where I see at the end of SPI.cpp, one SPI object defined: SPIClass SPI(VSPI);
(I might also do a quick check to see where VSPI was defined)... But I would then check to see how the pins were defined for this.
In SPI.h you see the definition: void begin(int8_t sck=SCK, int8_t miso=MISO, int8_t mosi=MOSI, int8_t ss=-1);
Which is why I wondered what SCK, MISO, MOSI are defined. Could do search again... Or simple program like I mentioned earlier...
Again once I think I know which pins are SPI - Run simple program on it. Usually for a simple device or again in my case anything and check with Logic Analyzer...

C) Wire, Uarts, ... - Like spi...

Once I think I have an understanding of the basic pieces, I would then start building up the pieces for your actual program.

If I then found that for example the screen was too flashy, I would first investigate how I was doing the screen updates. If I do something like: Clear screen and draw new stuff, then by design it will be flashy. I would first then look to see if I could do this in a more specific way. Example if outputting text field, instead of blanking the whole area, I would use Opaque text, and if necessary then blank out any area after the new write that did not overwrite the old value...

If that did not work or was too cumbersome and my processor had enough memory I would then try a logical frame buffer, Like I have in the ili9341_t3n ... _esp version. Again this makes it easy to do quick and dirty screen changes and then tell system to update.

And then if I was finding that the screen updates were taking too much of the CPU and I wanted to do other things quickly to get ready for the next update, I would then look into DMA... Again I have version of T3N library that uses DMA for updates. So once you build a display to update, you can tell system to start the update and then have the cpu do other things.

Again looking at the ESP32 manual the SPI system can use DMA... What capabilities does the DMA have? How to set it up? ... Is something one would have to investigate if one was interested.

But for myself - Back to playing with the Teensy!
 
Oh love my teensy's. The library is actually meant for just teensy 3.2 and higher. In my mind the more options a library is the more use it will get. In fact my prototype utilizes teensy 3.6. Since it has so much flash, I can make a pretty large graphical game.

Would be awesome if some one came up with a way to expand the flash by inventing an external flash chip. Or do they

Yea I think it's time to move the esp32 stuff back at thier site. But I really really appreciate the help you've given. You've given me some great starting points and taught me few things and even made me realize I know more than I think I do.

I'm hope to start real world testing tonight. I wanted to make every thing modular and I made a PDB with a switch for testing different voltages. My teensy was sucking down a 1500mah battery boosted to 5v in 45 minutes.

On the update I was worried about the bitmaps not changing when pressing a button. It should do that any way so I guess it was a silly question.



Again thank you for your time and help.
 
Last edited:
Well ain't that some $#!+!!!!!! Lol I just looked up the SMD chip itself and found a lil more info. I had found some of these modules that were spi flash boards for MP3 players. I asked on the arduino forum if these could be used to expand my flash and never got an answer. Oh well.

Ok so I looked the chip on the Bay and I can get one pre-mounted on a board. Around $10 US. Not bad. That solves so many problems and means that people with regular arduino can join in the fun. Now Im Looking for a ram module so any one can have color.

You guys rock

http://pages.ebay.com/link/?nav=item.view&alt=web&id=291956259182&globalID=EBAY-US

Can I run two spi devices on the same teensy?
 
Last edited:
Only $8.40 for 8Mbyte for prop_shield_lowcost.html - trusted source and includes audio amp - and you could run some RGB pixels too.

There are OSH boards around and other solutions - the 16 Mbyte Winbond chips are under $2 IIRC. FrankB made a board that will take RAM or FLASH - Paul posted some test boards - RAM or more $$$ for perhaps 128 KB - but that is SPI access too.
 
Would need both to upgrade the arduino boards. Though it looks easy enough you could just make your own.

Thing is every thing needs to be tiny enough to stuff in a case that actually fits in your pocket unlike the modern offerings of name brand consoles p. The prop shield looks nice and small and if it had a Ram chip or one could be installed it would be even better. Don't really know if I can solder an SMD. I tried once with a resistor that broke off a raspberry but in the end I just bought a new one.

Got any links to the other boards? I found Frank's board but unless I could order it pre soldered there's no way.
 
Last edited:
I hand soldered one of those SOIC8 Winbond 16's the other week with wire solder - after 8 pins dipped in rosin paste. That was easier than the ones I used solder paste on, though that can work - I've had a couple and wasn't sure if it was ebay chips or my heat abuse of the paste, or old paste - I cut some off and there was a non-binding dry oxide on a pin/pad not melted metal.

Prop shield won't do RAM and FLASH - comes with FLASH. RAM across SPI will have limiting factors of x-fer speed and caching to local ram for use and write back on change - not sure that RAM would be worth the trouble if avoidable.

Last two Flash I put onto a SOIC8 to DIP 8 adapter that was cheap on ebay - both work.Then just wire to data/power/gnd/clk per chip w/power cap and it worked. Some tips on web videos help with practice.
 
Ok this for kurts library....

Im playing around with the ESP32 veesion library that i found on thier site and was adding some extra grafx functions and what not. And i decided while im at it, to go ahead and kurts new stuff to my library as an else if kinda thing. Well i managed to get it all in after a couple fights with #endif but i cant get the typedef structure included. Would it be better to just add those bits to the private or the protected?
 
Ok I finally got around to testing the new libraries and I can't any thing on the screen. I used the standard pinout but I notice you have a TX and RX listed above. Where I connect these to? Do I need them.

If I run your library the blue light glows on the board but no picture. If I use the esp32 ili9341 from thier site the same. If I run an updated version of theirs with the gaming features I get nothing.
 
Last edited:
if you mean post #33? That is just a snip of a source file where those values are preset it looks like.

Does unmodified code work with expected connections?
 
I edited the last post. I cant any library to work. I'm gonna send a message to the manufacturer tomorrow. It got way to late tonight.

Its an ezsbc board not listed in the boards or variants.
 
Last edited:
Again have you tried any baby steps I mentioned in many posts?

Example does the SPI work at all?

How about running a simple SPI app that does something like:
Code:
#define PIN_SCK 18
#define PIN_MOSI 23
#define PIN_DC 5
#define PIN_CS 22

#define FILL_CHAR 0xfe
uint32_t clockRateSetting = 8000000;
#define DBGSerial Serial

void setup()
{
  while (!DBGSerial && millis() < 3000) ;
  DBGSerial.begin(115200);
  delay(100);
  DBGSerial.println("Start setup");
  pinMode(PIN_CS, OUTPUT);
  digitalWrite(PIN_CS, HIGH);
  DBGSerial.println("Before pinMode DC"); Serial.flush();
  pinMode(PIN_DC, OUTPUT);
  DBGSerial.println("Before SPI Begin"); Serial.flush();

  SPI.begin();
  DBGSerial.println("End Setup"); Serial.flush();


  uint8_t screenmemory[33];
  uint8_t retbuf[33];

void display_transfer_buf_verify(void)
{
  uint8_t i;

  DBGSerial.print("Verify transfer(MOSI-MISO: ");
  SPI.beginTransaction(SPISettings(clockRateSetting, MSBFIRST, SPI_MODE0));
  digitalWrite(PIN_CS, LOW);
  memset(retbuf, FILL_CHAR, sizeof(retbuf));  // init to some bogus value...
  SPI.transfer(screenmemory, retbuf, sizeof(retbuf) - 1);
  digitalWrite(PIN_CS_HIGH);
  SPI.endTransaction();
  for (i = 0; i < sizeof(retbuf) - 1; i++)  {
    if (screenmemory[i] != retbuf[i]) {
      DBGSerial.print("Mismatch found index: ");
      DBGSerial.print(i, DEC);
      DBGSerial.print(" W: ");
      DBGSerial.print(screenmemory[1], HEX);
      DBGSerial.print(" R: ");
      DBGSerial.println(retbuf[i], HEX);
      return;
    }
  }
  // Check last value still equal our fill character
  if (retbuf[sizeof(retbuf) - 1] != FILL_CHAR) {
    DBGSerial.print("End byte change: ");
    DBGSerial.println(retbuf[sizeof(retbuf) - 1], HEX);
  }
  else {
    DBGSerial.println("Succeeded");
  }
  delay(2000);  // Wait a couple of seconds. 
}

Warning, this was cut/paste with edits from test programs... So I may have missed something. But the idea is to try to send a number of bytes using SPI. Now run a jumper wire between MISO and MOSI pin and see if the data bytes get transferred. If so you have a pretty good idea that those pins are working.

Things that would concern me, include: looking at his schematic you see that there is an RGB led on the board, that appears to be connected with pins (16, 17, 18), Will it's use interfere with using pin 18 as the SCK pin for SPI? Or is it like Arduino boards who have the LED pin on 13?

So again with another baby step am I correct that that these three pins do RGB LED? I would maybe hack up a program like:
Code:
uint8_t counter = 0;
void setup() {
    // maybe do some Serial.... if needed
    pinMode(16, OUTPUT);
    pinMode(17, OUTPUT);
    pinMode(18, OUTPUT);
}
void loop() {
    counter++;
    if (counter == 8)
        counter = 0;
    digitalWrite(16, (counter & 1) ? HIGH : LOW);
    digitalWrite(17, (counter & 2) ? HIGH : LOW);
    digitalWrite(18, (counter & 4) ? HIGH : LOW);
    delay(250);
}
Does the LED turn on and change colors every .25 seconds?

Again if it were me I would use a Logic Analyzer to see all of the signals... If I did not have one, I would hack up a test harness..
Example use a Teensy, ( I would start with the one I had with the most memory. and maybe try simple test app, that maybe simply checks for one or more pins changing state. Then connect the teensy up to the ESP32 with ground wire plus connect the several pins that I think are SPI between them.

Then on Teensy, maybe do things like: digitalRead each of the pins between the two and if the state of a pin changes, print that a state changed... You can do that for each of the pins, to know that there is at least some state changing on the ESP32.

If at appears you can get those to talk, then maybe setup a trigger pin between the two boards, maybe use CS pin. and when it changes state, run the teensy in a quick loop, reading the logical, CS/DC/SCK/MISO/MOSI pins and try to capture for some brief amount of time or until you fill so much memory.

Then you can do some rudimentary printing of when you see that any of the states changed... To see if it logically makes sense...

And/or you might be able to setup to use the Teensy Logic Analyzer program to do all of this...

But again Baby steps!
 
ok when I use the program in post 26, I get these readings but no pin number..........

Code:
rst:0x10 (RTCWDT_RTC_RESET),BOOT:0X13 (SPI_FAST_FLASH_BOOT)
confugsip: 0, SPIWP:0X00
ckk_drv:, q_drv:0x00, d_drv:0x00, cs0_drv:0x00,hd_drv: 0x00
mode:DIO, clock div:1
load:0x3fff0008,len:8
load:0x3fff0010,len:2016
load:0x40078000,len:7780
ho 0 tail 12 room 4
load:0x40080000,len:252
entry 0x40080034
E (122) esp_image: invalid segment length 0xffffffff
E (122) boot: Failed to verify app image @ 0x10000 (8194)
user code done

when I run the first program in post #48, I get this error and the same serial monitor results as the above.

Code:
Arduino: 1.8.0 (Windows 7), TD: 1.34, Board: "ESP32 Dev Module, 80MHz, 115200, Debug"

C:\Users\duhjoker\Desktop\spi_test_part_2\spi_test_part_2.ino: In function 'void setup()':

spi_test_part_2:39: error: no matching function for call to 'SPIClass::transfer(uint8_t [33], uint8_t [33], unsigned int)'

   SPI.transfer(screenmemory, retbuf, sizeof(retbuf) - 1);

                                                        ^

In file included from C:\Users\duhjoker\Desktop\spi_test_part_2\spi_test_part_2.ino:6:0:

C:\Users\duhjoker\Documents\Arduino\hardware\espressif\esp32\libraries\SPI\src/SPI.h:67:13: note: candidate: uint8_t SPIClass::transfer(uint8_t)

     uint8_t transfer(uint8_t data);

             ^

C:\Users\duhjoker\Documents\Arduino\hardware\espressif\esp32\libraries\SPI\src/SPI.h:67:13: note:   candidate expects 1 argument, 3 provided

spi_test_part_2:40: error: 'PIN_CS_HIGH' was not declared in this scope

   digitalWrite(PIN_CS_HIGH);

                ^

spi_test_part_2:62: error: expected '}' at end of input

 }

 ^

exit status 1
no matching function for call to 'SPIClass::transfer(uint8_t [33], uint8_t [33], unsigned int)'

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


When I run the second test in #48 I get the same results as the first test at the top.
 
Last edited:
ok when I use the program in post 26, I get these readings but no pin number..........

Code:
...

E (122) esp_image: invalid segment length 0xffffffff
E (122) boot: Failed to verify app image @ 0x10000 (8194)
user code done
Those don't sound good! Failed to verify? Sounds like it is not properly being programmed!


when I run the first program in post #48, I get this error and the same serial monitor results as the above.

Code:
Arduino: 1.8.0 (Windows 7), TD: 1.34, Board: "ESP32 Dev Module, 80MHz, 115200, Debug"

C:\Users\duhjoker\Desktop\spi_test_part_2\spi_test_part_2.ino: In function 'void setup()':

spi_test_part_2:39: error: no matching function for call to 'SPIClass::transfer(uint8_t [33], uint8_t [33], unsigned int)'

   SPI.transfer(screenmemory, retbuf, sizeof(retbuf) - 1);
Again as I mentioned typed in on the fly so might be issues...
But try changing the SPI.transfer(screenmemory, retbuf, sizeof(retbuf) - 1) to
SPI.transferBytes(screenmemory, retbuf, sizeof(retbuf) - 1)

And again if your download of programs is givin you issues where it says invalid segment... and cound not verify image, than I wonder if you have had any luck with programming this board at all?

Update - FYI - If I run the last program that on yours I think should show LED with different colors, my console output shows:
Code:
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0x00
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0008,len:8
load:0x3fff0010,len:2036
load:0x40078000,len:9988
load:0x40080000,len:252
entry 0x40080034
 
Last edited:
Status
Not open for further replies.
Back
Top