Hi Tony,
One problem I can see is you are using a global FILE variable in sample() and write32(), but you never set it up, as when you open the file you assign it to a local variable. It is basically a typo, but:
FILE *fp; // defines a global variable called fp
void sample() {
// [snip]
fprintf(fp, "%c", b); // uses variable fp; no local variable called fp, so uses global
}
int main() {
FILE *fp = fopen("/local/out.snd", "w"); // defines a local variable called fp, and opens file
}
what you really want is:
int main() {
fp = fopen("/local/out.snd", "w"); // open file and assign to global variable
}
The other thing is a sample rate of 100us for writing every sample to flash sounds fast (FLASH writes are slow), but you'd have to do some tests to see what write rate you can sustain to flash (there were some benchmarks in the cookbook maybe).
There may be more, but this should help you get further.
Simon
I am trying to convert the Sound Recorder cookbook application to write to a local file 'out.snd' rather than the original serial usb link. I seem to be having lots of problems - even though I have commented out the write32 part of the code and attempted to use the timer to run it for just 1 second, it still crashes and leaves an empty file which I can only get at by keeping the reset button of the mbed pressed. If I dont enable the ticker interruot, I can get the first bit of text written to the file. The code is here - any help gratefully accepted: