I'm using the MCBSTM32C evaluation board. I would like to calculate the angle of the board in relation to the gravity vector. I have no prolems reading the accelerometer. I basically have the gravity vector components as int values. To do what I want to do I have to calculate the length of the vector using the sqrt function in math.h. The sqrt function expects double numbers as input and produces a double result as far as I can tell. I than would like to print the result onto the screen. As soon as I print to result onto the screen the program crashes. I'm not sure if it is the sqrt function which causes the trouble or the print function. Below is some code that leads to a crash. I can print any other value to screen just not double.
double acc_length; acc_length = sqrt(45.98745); sprintf(print_LCD[0], " %lf ", acc_length); GLCD_DisplayString (1, 0, 1, print_LCD[0]);
Thanks, Karsten
"I can print any other value to screen just not double."
it is fairly easy to debug it:
1) is the sqrt() function causing the crash? what if you just assign any double value to acc_length and comment out the sqrt() function. does the code still crash?
2) is the printf() function causing the crash? what if you assign a given string to print_LCD? does it still crash?
3) is the GLCD_Display() function causing the crash? what if you assign a given string to it? does it still crash?
4) sprintf(): i typically use sprintf(print_LCD, ...).
5) GLCD_Display(): check to see if it expects a null-terminated string (it typically does) and check to see if your sprintf() generates a null-terminated string.
As you say, it would be easy on any platform with just some simple source code changes.
But the OP has an MCBSTM32C:
www.keil.com/.../mcbstm32c_in_quickstart.htm
This has on-chip debug - making it even simpler to debug by just single-stepping, and inspecting variables.
"This has on-chip debug"
it doesn't matter - the point is that computers are incredibly simple as you can always take a logical approach to debug it.
Indeed.
"The most important tool for debugging is the one between your ears"