
Originally Posted by
sumotoy
Good question, even the tons of libraries for Flash chips for Arduino are not reliable at all, for example, I have several 512/1024 chip from Microchip and still now I cannot get working on my UNO. Some chip uses paged memory handle, some use direct addressing, so basically every chip needs it's own library. Are you using this library with Arduino Mini and witch SPI flash chip?
I am using this TFT library with the Mini and the flash chip is a WinBond W25Q80BV 1MB flash. I got the code for accessing the flash chip from this article http://www.instructables.com/id/How-...-Flash-Memory/. Here's the code that works on the Mini:
Code:
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <TFT_ILI9163C.h>
#include <Serial.h>
// WinBond flash commands
#define WB_READ_STATUS_REG_1 0x05
#define WB_READ_DATA 0x03
#define __CS 7
#define __DC 9
#define __RST 8
TFT_ILI9163C display = TFT_ILI9163C(__CS, __DC, __RST);
uint16_t displayRows = 128;
uint16_t numImages = 3;
byte pageBuf[256];
void setup() {
display.begin();
display.setBitrate(24000000);
display.clearScreen();
pinMode(3, OUTPUT); // backlight control
analogWrite(3, 255);
}
void loop() {
for (int i = 0; i < numImages; i++) {
for (int p = 0; p < displayRows; p++) {
read_page(p + (i * displayRows), pageBuf);
display.writedatabuffer(p, pageBuf);
}
delay(5000);
}
}
/* Read the WinBond W25Q80BV 1MB SPI flash.
Code adapted from Instructables article
http://www.instructables.com/id/How-to-Design-with-Discrete-SPI-Flash-Memory/
*/
void read_page(word page_number, byte *page_buffer) {
digitalWrite(SS, HIGH);
digitalWrite(SS, LOW);
SPI.transfer(WB_READ_DATA);
// Construct the 24-bit address from the 16-bit page
// number and 0x00, since we will read 256 bytes (one
// page).
SPI.transfer((page_number >> 8) & 0xFF);
SPI.transfer((page_number >> 0) & 0xFF);
SPI.transfer(0);
for (int i = 0; i < 256; ++i) {
page_buffer[i] = SPI.transfer(0);
}
digitalWrite(SS, HIGH);
not_busy();
}
void not_busy(void) {
digitalWrite(SS, HIGH);
digitalWrite(SS, LOW);
SPI.transfer(WB_READ_STATUS_REG_1);
while (SPI.transfer(0) & 1) {};
digitalWrite(SS, HIGH);
}
display.writedatabuffer() is just a function I added the TFT library to speed up writing each row:
Code:
void TFT_ILI9163C::writedatabuffer(uint16_t y, uint8_t *buf){
setAddrWindow(0,y,_width-1,y);
*rsport |= rspinmask;
*csport &= ~cspinmask;
// assume 256 byte buffer
for (int b = 0; b < 256; b++) {
spiwrite(buf[b]);
}
*csport |= cspinmask;
}
This is working well on the Mini as the attached image shows.

But I can't use the same code to access the flash chip when using the Teensy 3.1 - it looks like this TFT library uses advanced SPI features and the code is very different. What I want to know is how to write the equivalent code for the flash chip on the Teensy.
Hope this is clear enough.