??? 02/05/08 23:17 Read: times |
#150358 - answer to quiz! Responding to: ???'s previous message |
First clue: I said each of the 32 scenes required 8 bytes, so all scenes require a total of 256 bytes.
Second clue: I said that when stepping through the code, the page-write function always thought that it was told to write zero bytes. Third clue: the page-write function call used unsigned char as the type for the number-of-bytes-to-write argument. ----------------------------------------- Answer: what's the largest value of an unsigned char? 255, of course, and 256 is greater than 255. I used the sizeof() operator to fetch the size of my scene buffer in RAM to use as the number-of-bytes argument. So the compiler helpfully truncated 256 into 8 bits, resulting in ... zero. And so nothing was actually written to the flash, and at power-up I fetched garbage. The solution was to make the bytes-to-write parameter an unsigned int. (An alternative solution would have been to hard-code it and not pass that big a parameter but my flash-write code is supposed to be generic. But I was not worried about space and speed here so it works well enough as is.) ------------------------------------------ Crux of the biscuit for the OP: your reset and such is probably fine. Check your code! Make sure you're doing what you think you're doing! ------------------------------------------- Red herring: it seems like the 8051F314's internal SRAM is capable of retaining its memory for lots of minutes, or at least until the big electrolytics on the 3.3V rail finally bleed off. Since the micro was retaining its memory, I was fooled into thinking that the flash write was working when it wasn't. -a |