Hey everyone. Got a really weird problem. Here’s my code:
Serial.println(flashOffset, HEX);
SparkFlash_writeB(buffer, bufferSize, flashOffset)
Serial.println(flashOffset, HEX);
and here’s my function
bool SparkFlash_writeB(const uint8_t* buffer, int numByteToWrite, int extFlashOffset)
{
#ifdef VERBOSE
char buff[50];
// sprintf(buff,"SFWB1: Flash Offset: %d", extFlashOffset);
// Serial.println(buff);
sprintf(buff,"Writing %d bytes from %p to Ext Flash @ %x", numByteToWrite, buffer, 0x80000 + extFlashOffset);
Serial.println(buff);
#endif
int temp = 0;
int bytesWritten = 0;
for (int i=0;i<numByteToWrite;i++)
{
// Grab the current value of the image at positions i and i + 1 (two bytes))
temp = (buffer[i] << 8) + buffer[i+1];
// Write those values to flash
if(SparkFlash_write(extFlashOffset + i, temp) == 2)
{
bytesWritten += 2;
}
else
{
sprintf(buff,"Failed to write bytes @ %x", 0x80000 + i + extFlashOffset);
Serial.println(buff);
}
i++;
}
#ifdef VERBOSE
sprintf(buff,"SFWB2: Flash Offset: %d", extFlashOffset);
Serial.println(buff);
sprintf(buff,"Bytes Written: %d/%d'\n", bytesWritten, numByteToWrite);
Serial.println(buff);
Serial.println("Write Complete");
#endif
if(bytesWritten == numByteToWrite)
return true;
else
return false;
}
I’m writing around 6k bytes to external flash memory. flashOffset is passed as 0 but somehow becomes 0x3030 after this function is finished. If I keep
sprintf(buff,"SFWB2: Flash Offset: %d", extFlashOffset);
Serial.println(buff);
in my code flashOffset “stays” at 0 but when I comment it out it becomes 0x3303.
Ie, without the sprintf line I get the following out of the code above:
0
3030
With the sprintf line I get the following
0
0
What the hell is going on? Any ideas?

