cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Temperature Function With I/O on PC6

Rogers.Gary
Senior II
Posted on May 17, 2017 at 07:27

Hello:

Question 1:

A question that I cannot find an answer for. If I'm using PC6 (STM32F4) as a GPIO already, can I still configure and use the internal temperature sensor on ADC16?

Question 2:

Using the calibration constants stored in the device, and adding some extra calibration points if required, how accurate is the temperature sensor at ranges of -40C to +70C ?

Thanks...

Note: this post was migrated and contained many threaded conversations, some content may be missing.
11 REPLIES 11
AvaTar
Lead
Posted on May 17, 2017 at 07:58

The internal temperature is a separate channel (ADC1_IN16 on a F40x), i.e. connected to a separate ADC MUX input. You don't need (and cannot use) a GPIO for it.

For accuracy, the reference manuals says +-1.5°C. I never tested that, though.

It is obviously based on the forward voltage measurement of a p-n junction on the die.

See the reference manual (DM00031020, DocID018909) for details.

Rogers.Gary
Senior II
Posted on May 17, 2017 at 08:17

Hi, thanks for this. What I meant by the question is, can I *also* use a GPIO at the same time?

Posted on May 17, 2017 at 08:50

Yes.

The temperature sensor is not associated with any 'alternate function' of a GPIO pin.

What is true, you can't use a pin as GPIO and as ADC input channel at the same time. But that is true for any other alternate function as well.

BTW, you have not specified which MCU you talking about. On a F407 (on the F4 Disco board), PC6 has no analogue alternate function.

Posted on May 17, 2017 at 15:52

Hi, sorry, it should have been written. It is the STM32F405VG / 100 pin device.

To clarify, I want to use an already assigned GPIO (control a relay) to PC6, but add the ability to measure temperature on ADC16 (PC6)

I noticed that in configuring the temperature sensor, it did not assign using the normal 'AF' call, and thus my question.

So it DOES appear it can be done on this device then? If so, that's terrific.

Thanks so much for your help.

Posted on May 17, 2017 at 17:08

Hello roofie01

As already mentioned, on the F405VG there is no physical link between the ADC1 Input IN16 and the GPIO PC6.

The ADC IN16 Channel is internally connected and reserved to the internal temperature sensor.

PC6 has no analog functions and can be used in digital mode or Alternate functions (UART, TIM, SDIO ...)

When configuring ADC1 using internal temperature sensor, you do not have any GPIO configuration to do, but only the configuration of the IN16 Channel of the ADC1 (Rank)

Regards

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on May 17, 2017 at 17:59

Roman,

Thanks for the clarification, and I'm presently trying the sensor. In the reference manual (electrical) on page 134, it has a table with the address for 30C and 110C. I'm confused in that it gives 2 addresses for example for TS_CAL_1:

0x1FFF 7A2C - 0x1FFF 7A2D

From the manual, I'm using it as per the formula:

What does this mean?  I am trying to use it as such (thanks to person that wrote this example)

&sharpdefine TEMP110_CAL ((uint16_t*) ((uint32_t) 0x1FFF7A2C))   //just used the first one

&sharpdefine TEMP30_CAL ((uint16_t*) ((uint32_t) 0x1FFF7A2E))   //just used the first one

&sharpdefine VDD_CALIB ((uint16_t) (330))      

&sharpdefine VDD_APPLI ((uint16_t) (328))   

uint16_t TS_DATA = ADC_GetConversionValue(ADC1); //Return the converted data        

double processorTemp;   

 processorTemp     =  (double) TS_DATA * VDD_APPLI / VDD_CALIB /16;

 processorTemp -=  (double) TEMP30_CAL;

 processorTemp *=  (double) (110 - 30);

 processorTemp /=  (double)TEMP110_CAL- TEMP30_CAL);    

 processorTemp +=   30;        

 uint32_t processorTemperature =  (int32_t) ((double)processorTemp *100);

 

printf('temperature = %i\n\n', processorTemperature);       

The numbers I am seeing are 39025, 39030, etc.

Obviously a gross problem. What could be wrong?

Thanks....again.

Posted on May 17, 2017 at 18:07

I'm confused in that it gives 2 addresses for example for TS_CAL_1:

0x1FFF 7A2C - 0x1FFF 7A2D

It's a 16-bit value (in fact 12-bit, simply the value read out from ADC in the factory), so 2 bytes.

 processorTemp     =  (double) TS_DATA * VDD_APPLI / VDD_CALIB /16

Why the /16?

Also note, that the readout will be significantly noisy especially if read out while processor is running; and that it indicates the internal temperature of the chip, not the ambient temperature.

JW

Posted on May 17, 2017 at 18:25

Hi,

Got it working - simplified to example from manual:

uint16_t calcTemp =  ( ( (110 - 30)*(TS_DATA - *TEMP30_CAL) ) / (*TEMP110_CAL - *TEMP30_CAL) ) + 30;

Also configured the GPIO for reads, and it works as well.

Thanks so much for your help!

Posted on May 17, 2017 at 18:30

jw,

As indicated in a post below it is now working. A silly design error on my board forced me to resort to using the internal sensor, and I must use it for ambient. It can be out +/- 3 to 5 degrees. I need to measure -40C to about +60C. Instant temperature isn't  required, so I was planning on using a moving exponential filter to smooth the values.

What are your thoughts...comments? Is this possible?

Thanks for your opinion...