stm32f103 clones

Anything not related to STM32
Post Reply
ag123
Posts: 1918
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

stm32f103 clones

Post by ag123 »

ag123
Posts: 1918
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: stm32f103 clones

Post by ag123 »

the actual post for a follow-up is this:

I tested out the temperature sensor for a blue pill, the stm32f103c8 has a poor marking and is possibly clone
'most' things work, I get the RTC freeze issue every once in a wrong sequence of ops.
then I happened to test out the temperature sensor

so checking the specs
https://www.st.com/resource/en/datashee ... f103c8.pdf
5.3.19 Temperature sensor characteristics
V25 min 1.34, typ: 1.43, max: 1.52
slope: 4.3 mV / deg C

Code: Select all

	// specs 5.3.19 temp sensor characteristics
	// V 25 deg ~ 1.43v
	// slope 4.3 mv/C
	float temp = (mv - 1430) * 1.0 / 4.3 + 25.0;

when run based on specs the calc goes
temp sensor analogRead:1597, mvolt:1271, temp(deg C:)-11.98
temp sensor analogRead:1590, mvolt:1266, temp(deg C:)-13.14
room temperature is 30 deg C (around there)

I'm initially thinking that I may have a 'defective' stm32, then I did some tests
I used a value of 1.26 V ~ 28 deg C as the datum and reworked the linear projection.
I tried to warm up the chip, but instead of higher readings, the calculated temperature actually drops and is inconsistent.

this goofy behavior leads to a guess that the chip is after all a clone rather than a real stm32.
trimarco232
Posts: 44
Joined: Wed Jul 12, 2023 11:09 am
Answers: 1

Re: stm32f103 clones

Post by trimarco232 »

Hi ag123,
interesting !
please what is the relation between analogRead and mvolt ?
I made 3v3 *1000 /4095 and did not get the same result
ag123
Posts: 1918
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: stm32f103 clones

Post by ag123 »

the equation in the previous post is correct, the parameters are stated in section 5.3.19 Temperature sensor characteristics
https://www.st.com/resource/en/datashee ... f103c8.pdf

I think for STM core, there is a #define or call to set the number of bits returned by ADC
https://github.com/stm32duino/Arduino_C ... alog.h#L60

Code: Select all

 * \brief Set the resolution of analogRead return values. Default is 10 bits (range from 0 to 1023).
 *
 * \param res
 */
extern void analogReadResolution(int res);
so first call

Code: Select all

void setup() {
	pinMode(PAxx, INPUT_ANALOG); // etc
	analogReadResolution(12);
}
https://github.com/stm32duino/Arduino_C ... API#analog
^ according to documentation, it seemed you can read the ADC value using

Code: Select all

uint16_t value = analogRead(ATEMP);
I think after that you can use

Code: Select all

 	float mVolt = value / 4096 * 3.3 * 1000; // convert to millivolt
then plug into the equation to get temperature

Code: Select all

	// specs 5.3.19 temp sensor characteristics
	// V 25 deg ~ 1.43v
	// slope 4.3 mv/C
	float temp = (mVolt - 1430) * 1.0 / 4.3 + 25.0;
past experience seem to show that some 'clone' stm32 (i.e. not stm32) but deem 'compatible' this calculation don't match real temperature.

so put the code together in loop look like this

Code: Select all

void setup() {
	// pinMode(ATEMP, INPUT_ANALOG); // I'm not sure if this is needed at all
	analogReadResolution(12);
}

void loop() {
	uint16_t value = analogRead(ATEMP);
 	float mVolt = value * 1000 / 4096 * 3.3 ; // convert to millivolt
	// V 25 deg ~ 1.43v
	// slope 4.3 mv/C
	float temp = (mVolt - 1430) * 1.0 / 4.3 + 25.0;
	Serial.print("temp (deg C): ");
	Serial.println(temp);
	delay(1000);
}
ag123
Posts: 1918
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: stm32f103 clones

Post by ag123 »

if you use temperature sensor to try to tell stm32f103 clones apart, maybe this may be one check, I'm not sure if it is always true.

but if you want to measure temperatures, it is more accurate to use one of those temperature sensors,
e.g. termistors say 100 k thermistors e.g.
https://www.gotronic.fr/pj2-mf52type-1554.pdf

just search thermistors in aliexpress and you get lots of entries, you can add keyword 3950 (deem the beta value) and it narrow to thermistors with lots of ads.

thermistors may need quite a bit of calibration as 'all' thermistors on aliexpress claim to be 3950, then I've a 100 k thermistor that read 5k at 25 deg C, it is suppose to be 100k, lots of nonsense

for something very precise and pre-calibrated use semiconductor temperature sensor
e.g. LMT86
https://www.ti.com/product/LMT86
https://www.ti.com/lit/ds/symlink/lmt86.pdf
can find on LCSC and of course digiKey, element14, mouser etc
https://lcsc.com/product-detail/Tempera ... _z=n_lmt86
think possible to find on aliexpress as well, but check for more reputable ones (e.g. the reviews)

there are also LM135 / LM235 / LM335 etc
https://www.ti.com/product/LM335
https://www.ti.com/lit/ds/symlink/lm335.pdf
even ST make this part
https://www.st.com/en/mems-and-sensors/lm135.html
but on aliexpress be wary of fakes

lm35
https://www.ti.com/product/LM35
https://www.ti.com/lit/ds/symlink/lm35.pdf
(I bought lm35 from aliexpress once turn out to be fake, I think it is just plastic with 3 wires, it is not even a transistor)
i got 'angry' after that and ordered LMT86 from a 'reputable' (premium) source (e.g. digiKey etc, I bought from element14.com (farnell) )
it isn't about them the fake lm35 being pricey and fake, but waste days trying to figure out why it didn't work.

then for digital ones a lot of them e.g. DS18B20
https://www.analog.com/media/en/technic ... s18b20.pdf
lots in aliexpress
https://www.aliexpress.com/w/wholesale-ds18b20.html
Post Reply

Return to “Off topic”