From 7c4424e08e97723a6c17d491bc71ea648093cf40 Mon Sep 17 00:00:00 2001 From: Felix Rusu Date: Mon, 30 Jun 2014 11:25:09 -0400 Subject: [PATCH] Fix writeBytes length Credit to wilsynet --- SPIFlash.cpp | 6 +++--- SPIFlash.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SPIFlash.cpp b/SPIFlash.cpp index a0538da..20d1960 100644 --- a/SPIFlash.cpp +++ b/SPIFlash.cpp @@ -176,12 +176,12 @@ void SPIFlash::writeByte(long addr, uint8_t byt) { /// WARNING: if you write beyond a page boundary (or more than 256bytes), /// the bytes will wrap around and start overwriting at the beginning of that same page /// see datasheet for more details -void SPIFlash::writeBytes(long addr, const void* buf, uint8_t len) { +void SPIFlash::writeBytes(long addr, const void* buf, uint16_t len) { command(SPIFLASH_BYTEPAGEPROGRAM, true); // Byte/Page Program SPI.transfer(addr >> 16); SPI.transfer(addr >> 8); SPI.transfer(addr); - for (uint8_t i = 0; i < len; i++) + for (uint16_t i = 0; i < len; i++) SPI.transfer(((byte*) buf)[i]); unselect(); } @@ -228,4 +228,4 @@ void SPIFlash::wakeup() { /// cleanup void SPIFlash::end() { SPI.end(); -} +} \ No newline at end of file diff --git a/SPIFlash.h b/SPIFlash.h index be049d4..20863c1 100644 --- a/SPIFlash.h +++ b/SPIFlash.h @@ -77,7 +77,7 @@ public: byte readByte(long addr); void readBytes(long addr, void* buf, word len); void writeByte(long addr, byte byt); - void writeBytes(long addr, const void* buf, byte len); + void writeBytes(long addr, const void* buf, uint16_t len); boolean busy(); void chipErase(); void blockErase4K(long address);