KrisKasprzak
Well-known member
Writing to the Windbon flash chip
All,
I have a library to write to the Teensy approved Windbon chip and to date has been 100% reliable in writing/reading data. I'll estimate I've written some 100 mb and have not lost even 1 bit.
My library writes byte-by-byte and NOT arrays or bytes in sequence, although the data sheet claims you can write pages up to 255 bytes in one shot. You can imagine the byte-by-byte overhead slows things down where on average each byte takes around 34 us to write. I tried to write bytes in sequence and performance is around 12 us/byte. But.... I get a failed writes every 500 to 1000 bytes. Totally unacceptable.
Not shown are the raw data sent to the function but the byte conversion is correct.
Reading the chip and converting bytes to data (note the nan)
Record 0298, 1, 298, 2.72959, 0.24814, 0
Record 0299, 1, 299, 2.72959, nan, 0
looking at the raw data on the chip see 153-255-255-255 for the float--should be similar to row above
Address: 10430, Record: 298 - 82-101-99-111-114-100-32-48-49-52-56-0-0-0-0-0-0-0-0-0-0-1-0-0-0-148-153-177-46-64-153-25-126-62-0-
Address: 10465, Record: 299 - 82-101-99-111-114-100-32-48-49-52-57-0-0-0-0-0-0-0-0-0-0-1-0-0-0-149-153-177-46-64-153-255-255-255-0-
Unless something jumps out. I'm happy leaving things alone.
Thanks in advance.
All,
I have a library to write to the Teensy approved Windbon chip and to date has been 100% reliable in writing/reading data. I'll estimate I've written some 100 mb and have not lost even 1 bit.
My library writes byte-by-byte and NOT arrays or bytes in sequence, although the data sheet claims you can write pages up to 255 bytes in one shot. You can imagine the byte-by-byte overhead slows things down where on average each byte takes around 34 us to write. I tried to write bytes in sequence and performance is around 12 us/byte. But.... I get a failed writes every 500 to 1000 bytes. Totally unacceptable.
Not shown are the raw data sent to the function but the byte conversion is correct.
Reading the chip and converting bytes to data (note the nan)
Record 0298, 1, 298, 2.72959, 0.24814, 0
Record 0299, 1, 299, 2.72959, nan, 0
looking at the raw data on the chip see 153-255-255-255 for the float--should be similar to row above
Address: 10430, Record: 298 - 82-101-99-111-114-100-32-48-49-52-56-0-0-0-0-0-0-0-0-0-0-1-0-0-0-148-153-177-46-64-153-25-126-62-0-
Address: 10465, Record: 299 - 82-101-99-111-114-100-32-48-49-52-57-0-0-0-0-0-0-0-0-0-0-1-0-0-0-149-153-177-46-64-153-255-255-255-0-
Unless something jumps out. I'm happy leaving things alone.
Code:
byte by byte write method for float (which is 100% reliable)
// convert float to 4 bytes, 100% reliable
WriteData(aBytes[0]);
WriteData(aBytes[1]);
WriteData(aBytes[2]);
WriteData(aBytes[3]);
void BulletDB::WriteData(uint8_t data) {
SPI.beginTransaction(SPISettings(SPEED_WRITE, MSBFIRST, SPI_MODE0));
digitalWriteFast(cspin, LOW);
SPI.transfer(WRITEENABLE); // write instruction
digitalWrite(cspin, HIGH);
SPI.endTransaction();
flash_wait_for_write = 1;
write_pause();
SPI.beginTransaction(SPISettings(SPEED_WRITE, MSBFIRST, SPI_MODE0));
digitalWriteFast(cspin, LOW);
SPI.transfer(WRITE); // write instruction
SPI.transfer((uint8_t) ((Address >> 16) & 0xFF));
SPI.transfer((uint8_t) ((Address >> 8) & 0xFF));
SPI.transfer((uint8_t) (Address & 0xFF));
SPI.transfer(data);
digitalWriteFast(cspin, HIGH);
SPI.endTransaction();
flash_wait_for_write = 1;
write_pause();
Address = Address + 1;
}
Code:
sequential byte write method for a float (which is very unreliable)
// convert float to 4 bytes in array called aBytes (which is a global array in my lib)
WriteData(4); // 100% reliable
void BulletDB::WriteBytes(uint8_t Length) {
uint8_t i = 0;
SPI.beginTransaction(SPISettings(SPEED_WRITE, MSBFIRST, SPI_MODE0));
digitalWriteFast(cspin, LOW);
SPI.transfer(WRITEENABLE);
digitalWrite(cspin, HIGH);
SPI.endTransaction();
flash_wait_for_write = 1;
write_pause();
SPI.beginTransaction(SPISettings(SPEED_WRITE, MSBFIRST, SPI_MODE0));
digitalWriteFast(cspin, LOW);
SPI.transfer(WRITE);
SPI.transfer((uint8_t) ((Address >> 16) & 0xFF));
SPI.transfer((uint8_t) ((Address >> 8) & 0xFF));
SPI.transfer((uint8_t) (Address & 0xFF));
for (i = 0; i < Length; i++){
SPI.transfer((uint8_t) aBytes[i]);
}
digitalWriteFast(cspin, HIGH);
SPI.endTransaction();
flash_wait_for_write = 1;
write_pause();
Address = Address + Length;
}
Thanks in advance.