Hi Guys,
Just made a lap timer on my mega1284. And it works pretty well - I have it printing the values to my terminal however I am trying to write the data to sd card. If I replace the code that reads button presses and stores the “time gap” between presses in an array with arbitrary values in the array positions, it has no problem writing to the sd card - so the code that writes to the sd card is fine:
printf("7 clicks in total\n");
res = f_open(&fl1, "0:rotor.txt", FA_CREATE_ALWAYS | FA_WRITE); //open file to write to
if (res != FR_OK) {
printf("file open failed, reason: %d\n", res);
}
// *****initiating timings******************************** /
while (PINB&(1<<PB4)); // loop here until first button press
timer_tick=0;// here is where we start timing
_delay_ms(10); // delay for 10 ms to debounce button press
while (!(PINB&(1<<PB4))); // loop here until button is released
_delay_ms(10); // delay for 10 ms to debounce button release
//cumulative timings. j is 0 - 5 because first press is above
for (j=0;j<6;j++){
while (PINB&(1<<PB4)); // loop here until second button press
rotor[j] = (double)timer_tick/1000; //get the value of the millisecond counter
_delay_ms(10); // delay for 10 ms to debounce button press
printf("[%d] time: %f\n",j+1, rotor[j]);
while (!(PINB&(1<<PB4))); // loop here until button is released
}
printf("storing data\n");
printf("%.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n\n", rotor[0], rotor[1], rotor[2], rotor[3], rotor[4], rotor[5]);
sprintf(stringwrite, "%.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", rotor[0], rotor[1], rotor[2], rotor[3], rotor[4], rotor[5]);
int stringlength = strlen(stringwrite);
printf("length = %d\n",stringlength);
res = f_write(&fl1, stringwrite, strlen(stringwrite), &s2); //write to file
if (res != FR_OK)
{
printf("write failed: %d\n", res);
}
printf("finished writing\n");
f_close(&fl1);
So the user presses the button 7 times to store 6 times. They appear nicely on the terminal. It then prints a string to the terminal of those times. All good. It then creates a string with sprintf, prints the length of the string and tries to save that to the sd card. It hangs though at
printf("length = %d\n",stringlength);
As I said, if I replace all the code that actually collects the timings with just arbitrary values stored in the array rotor[] it has no issues writing to the sd card.
Any ideas?
Cheers guys