So, I'm starting to learn how to use the STM32CUBE IDE.
I’m not using the Nucleo boards because those cost a fortune here in Brazil, and I’m not paying a sizable chunk of the minimum wage here when I can solve my cravings for knowledge with the cheap Blue Pill and Black Pill from Shopee.
In this useless-but-usefull-for-learning project I've set up for accomplishing those things:
/?action=dlattach;attach=1651475;image)
1 - Programing 2 STM32 MCUs to comunicante via SPI under a simple protocol;
2 - In the Master (STM32F411 aka "Black Pill"), use a 16x2 generic I2C display to show important information;
3 - In the Slave (STM32F103 aka "Blue Pill"), use DMA to acquire data from the ADC, average the data 200 times and than sent to the master when required to.
Ok, so far so good, very basic stuff, bla bla bla. I made an overcomplicated thermometer and I’m not ashamed. The slave reads a the analog voltage from a PTC 200 times via DMA, averages it, puts the 12 bits of data in two bytes of a buffer and sends it when the master requests it. The Master then puts those 2 bytes back together into a short integer, does the necessary conversion to celcius into a float and then sends to the display. The 16x2 display requires that each character from the temperature is an ASCII char. Naturally,
stdllib has a function called
gcvtf(); that does just that.
In a previous version of the code, I was using
itoa(); to display just the data before the decimal point (I was converting the 2 bytes read from de SPI to a short int) and the code compiled and uploaded fine. I got greedy and tried to measure .1 and .01 resolution (just to see the fluctuation of the measurements from noise and that sort of thing) using
gcvtf();. This time I received a warning, the function was not compiled but the code uploaded without it

. The temperature displayed was 0 (the preloaded value from the float used to store the conversion).
I scratched my head for hours and then I had the idea to look further inside the header file of the
stdlib. I copied the function prototype of the
gcvtf(); to a location where the
itoa(); was declared (inside a
#if #endif block) and it worked!
/?action=dlattach;attach=1651469;image)
A quick fix, I know, but it worked.
I could implement my own
gcvtf();, but why bother when it's done already? No need to reinvent the wheel, right?
Why did I had to go through all this trouble to use an
stdlib function that should be available? Am I missing something?