cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1

Anonymous
Not applicable

In the PSoC1 example project CE82235 is hidden an ugly programming error.

   

The project reads an ADC voltage, converts it to a float number and displays the result on the LCD. Part of this conversion is ussing ftoa(). The declarations are as follows:

   

 

   

int*status;

   

LCD_PrString(ftoa(Voltage,status));

   

 

   

Though this is syntactically correct, the author did not follow the usual C-linkage needed. Sinc C only knows "reference by value" for parameters, it is required to specify the address for a parameter that is used to give back a value (like the staus).

   

Since the *status" is not initialized within the project it is pointing into electronic nirwana giving unpredictable results (modifying memory address zero and one(1)).

   

What should have been written was:

   

 

   

int status;

   

LCD_PrString(ftoa(Voltage,&status));

   

 

   

I did not check for similarities in other projects that used ftoa yet, but it may be worth checking for.

   

 

   

Happy coding

   

Bob

0 Likes
4 Replies
Bob_Marlowe
Expert II

I do not know why the system assumes me to be "WeiBiao". I did not change my name, I'm still "Bob". Where do I get the 10 redeem points from that are due to me?

   

 

   

Bob

0 Likes
Anonymous
Not applicable

The real WeiBaio would be happy to get extra 10 points. 🙂

0 Likes
Bob_Marlowe
Expert II

It is not much he will get for 110 points, so he may keep them.

   

Bob

0 Likes
Anonymous
Not applicable

 One can get a T-shirt for 100 points. Not bad.

0 Likes