darioconcilio
Well-known member
Hi guys,
I writed a simple project because I'm trying to overwrite a config file with different value, but it seems that it not takes effect.
Synthesizing...
This sketch read MYFILE.CFG, that contains 81 chars, afterthat it waits an input 1, 2, or 3, then it tryes to overwrite content file with new information (new 81 chars)
I'm using Flash memory S25FL256S, and I connect in this way (Attached 16-Lead):
HOLD (FLASH) => VCC (Teensy3.2)
VCC => VCC
CS => PIN 9 (CS)
SO/IO1 => PIN 12 (DIN)
SCK => PIN 14 (CLK)
SI/IO0 => PIN 11 (DOUT)
WP#/IO2 => VCC
VSS => GND
NOTE: I already created MYFILE.CFG (into flash) using CopyFromSD sketch (first time), It works all.
Using this sketch, I found this monitor event message...
[Serial Monitor]
Init FLASH connection: OK
Opening file MYFILE.CFG ...done.
Loading data... done.
000025512500012550000000002100000255000325500000000040000000000005150601570158000
[In this point insert, for ex. char "1"]
Opening file MYFILE.CFG ...done.
Writing file 1 ... done.
[It waits 10 second and try to read file again]
Opening file MYFILE.CFG ...not found!!!
I tryed to use erase method also, but it seems not work.
If I reset Teensy 3.2, I found original content file showed above.
Where I wrong?!?
I writed a simple project because I'm trying to overwrite a config file with different value, but it seems that it not takes effect.
Synthesizing...
This sketch read MYFILE.CFG, that contains 81 chars, afterthat it waits an input 1, 2, or 3, then it tryes to overwrite content file with new information (new 81 chars)
I'm using Flash memory S25FL256S, and I connect in this way (Attached 16-Lead):
HOLD (FLASH) => VCC (Teensy3.2)
VCC => VCC
CS => PIN 9 (CS)
SO/IO1 => PIN 12 (DIN)
SCK => PIN 14 (CLK)
SI/IO0 => PIN 11 (DOUT)
WP#/IO2 => VCC
VSS => GND
NOTE: I already created MYFILE.CFG (into flash) using CopyFromSD sketch (first time), It works all.
Using this sketch, I found this monitor event message...
[Serial Monitor]
Init FLASH connection: OK
Opening file MYFILE.CFG ...done.
Loading data... done.
000025512500012550000000002100000255000325500000000040000000000005150601570158000
[In this point insert, for ex. char "1"]
Opening file MYFILE.CFG ...done.
Writing file 1 ... done.
[It waits 10 second and try to read file again]
Opening file MYFILE.CFG ...not found!!!
I tryed to use erase method also, but it seems not work.
If I reset Teensy 3.2, I found original content file showed above.
Where I wrong?!?
Code:
#include <SerialFlash.h>
#include <SPI.h>
#define FLASH_CS_PIN 9 //Serial FlashControllo
#define FLASH_MOSI_PIN 11 //Serial FlashLettura
#define FLASH_MISO_PIN 12 //Serial FlashScrittura
#define FLASH_SCK_PIN 14 //Serial FlashClock di comunicazione
#define MESSAGE_LENGTH 81
const char* fileName = "MYFILE.CFG";
const char* set1 = "000000025500012550000000002000000255000325500000000040000000000005150601570158002";
const char* set2 = "025500025500012550000000002000123255000325504600000040000000000005150601570158000";
const char* set3 = "012500025500012550000000002000100255000325512800000040000000000005150601570158001";
SerialFlashFile configFile;
void setup() {
SPI.setSCK(FLASH_SCK_PIN);
SPI.setMOSI(FLASH_MOSI_PIN);
SPI.setMISO(FLASH_MISO_PIN);
while (!Serial) ;
delay(100);
//Init
initFlashMemory();
//First reading
readConfig();
}
void loop() {
if (Serial.available() > 0) {
byte inByte = Serial.read();
writeConfig(inByte);
delay(10000);
readConfig();
}
}
void initFlashMemory() {
Serial.println("OK");
Serial.print("Init FLASH connection: ");
if (!SerialFlash.begin(FLASH_CS_PIN)) {
while (1) {
Serial.println("Unable to access the flash memory");
delay(500);
}
}
Serial.println("OK");
}
void readConfig(void) {
Serial.print("Opening file ");
Serial.print(fileName);
Serial.print(" ...");
if (SerialFlash.exists(fileName)) {
configFile = SerialFlash.open(fileName);
byte data[MESSAGE_LENGTH];
Serial.println("done.");
Serial.print("Loading data... ");
configFile.read(data, MESSAGE_LENGTH);
configFile.close();
Serial.println("done.");
for (byte i = 0; i < MESSAGE_LENGTH; i++) {
Serial.print((char)data[i]);
}
Serial.println();
}
else
Serial.println("not found!!!");
}
void writeConfig(byte setId) {
Serial.print("Opening file ");
Serial.print(fileName);
Serial.print(" ...");
if (SerialFlash.exists(fileName)) {
configFile = SerialFlash.open(fileName);
byte data[MESSAGE_LENGTH];
Serial.println("done.");
if (setId == 1) {
for (byte i = 0; i < MESSAGE_LENGTH; i++)
data[i] = (byte) set1[i];
} else if (setId == 2) {
for (byte i = 0; i < MESSAGE_LENGTH; i++)
data[i] = (byte) set2[i];
} else if (setId == 3) {
for (byte i = 0; i < MESSAGE_LENGTH; i++)
data[i] = (byte) set3[i];
}
// Serial.print("Erasing file ...");
// configFile.erase();
// Serial.println("done.");
Serial.print("Writing file ");
Serial.print((char)setId);
Serial.print(" ... ");
configFile.write(data, MESSAGE_LENGTH);
configFile.close();
Serial.println("done.");
}
else
Serial.println("not found!!!");
}
Attachments
Last edited: