cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 Discovery Reading ts_cal1 and ts_cal2 from system memory

RomainR.
ST Employee
Posted on June 20, 2013 at 22:30

Hi,

I

'm desperate to not achieve my project with

the

internal

temperature

sensor

of

STM32F0

For now I

try to read

the

sensor

factory

calibration

data

stored in the

system memory

by simple

pointer

that way.

(53) uint16_t ts_cal1, ts_cal2;

(54) ts_cal1 = *(uint16_t*)(0x1FFFF7B8);

(55) ts_cal2 = *(uint16_t*)(0x1FFFF7C2);

The KEIL compiler does not

appreciate

...

..\main.c(55): error:  &sharp77-D: this declaration has no storage class or type specifier

..\main.c(55): error:  &sharp28: expression must have a constant value

Do

you have any advice

or

tell me what

I forgot

?

Also,

is

that

one

of you

has already managed

to use

the formula in the

datasheet

Temperature

(in

� C) =

{

(

V25

-

VSENSE

)

/

Avg_Slope

}

+

25

?

Thanks.

#internal-temperature-sensor #internal-temperature-sensor

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.

4 REPLIES 4
Posted on June 20, 2013 at 22:49

It probably doesn't like the way you have the parenthesis

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Internal%20temperatur%20sensor&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=154]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FInternal%20temperatur%20sensor&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=154
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
RomainR.
ST Employee
Posted on June 21, 2013 at 08:35

By this way. It seems to be OK. No build error. I need to check with the HW now

#define ts_cal1 = *((uint16_t*) 0x1FFFF7B8);

#define ts_cal2 = *((uint16_t*) 0x1FFFF7C2);

Thank Clive1

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.

RomainR.
ST Employee
Posted on June 23, 2013 at 17:38

Internal Temperature sensorwork fine on STM32F0 Discovery. Here the code to save time.


/* Includes ------------------------------------------------------------------*/

#include ''stm32f0xx.h'' 

#include ''stm32f0_discovery.h'' 


/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

#define TS_CAL1 *((uint16_t*) 0x1FFFF7B8) // TS_CAL1 = 1767 

#define TS_CAL2 *((uint16_t*) 0x1FFFF7C2) // TS_CAL2 = 1343 

#define AVG_SLOPE (float)((TS_CAL1 - TS_CAL2)/0) 


/* Private variables ---------------------------------------------------------*/

static
volatile
uint32_t TimingDelay; 

uint32_t 
clock
=0; 

const
uint16_t V25 = 1963; 
// V25=1.43V at ref 3.0V 

uint16_t VSense; 

float
Temp; 


/* Private function prototypes -----------------------------------------------*/

void
TimingDelay_Decrement(
void
); 

void
Delay(__IO uint32_t nTime); 

void
Int_Temp_Sensor_Config(
void
); 

float
Get_Int_Temp(
void
); 


/* Private functions ---------------------------------------------------------*/


void
Int_Temp_Sensor_Config(
void
) 

{ 

ADC_InitTypeDef ADC_InitStructure; 

ADC_StructInit(&ADC_InitStructure); 


RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); 


ADC_DeInit(ADC1); 

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; 

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; 

ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; 

ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward; 

ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; 

ADC_Init(ADC1, &ADC_InitStructure); 

ADC_ChannelConfig(ADC1, ADC_Channel_16, ADC_SampleTime_239_5Cycles); 

ADC_TempSensorCmd(ENABLE); 

ADC_GetCalibrationFactor(ADC1); 


ADC_Cmd(ADC1, ENABLE); 

while
(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN)); 

ADC_StartOfConversion(ADC1); 

} 



float
Get_Int_Temp(
void
) 

{ 

while
(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); 

VSense = ADC_GetConversionValue(ADC1); 

return
(
float
)(((V25 - VSense)/AVG_SLOPE)+25); 

} 


/** 

* @brief Main program. 

* @param None 

* @retval None 

*/

int
main(
void
) 

{ 

/*!< At this stage the microcontroller clock setting is already configured, 

this is done through SystemInit() function which is called from startup 

file (startup_stm32f0xx.s) before to branch to application main. 

To reconfigure the default setting of SystemInit() function, refer to 

system_stm32f0xx.c file 

*/


RCC_ClocksTypeDef RCC_Clocks; 


/* SysTick end of count event each 1ms */

RCC_GetClocksFreq(&RCC_Clocks); 

SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000); 


/* Initiate Blink Speed variable */

clock
=SystemCoreClock; 


/* Configure LED3 and LED4 on STM32F0-Discovery */

STM_EVAL_LEDInit(LED3); 

STM_EVAL_LEDInit(LED4); 

STM_EVAL_LEDOff(LED3); 

STM_EVAL_LEDOff(LED4); 


/* Initialize User_Button on STM32F0-Discovery */

STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); 


Int_Temp_Sensor_Config(); 


while
(1) 

{ 

STM_EVAL_LEDOff(LED4); 

Temp = Get_Int_Temp(); 

Delay(5000); 

STM_EVAL_LEDOn(LED4); 

Delay(500); 

} 


/** 

* @brief Inserts a delay time. 

* @param nTime: specifies the delay time length, in 1 ms. 

* @retval None 

*/

void
Delay(__IO uint32_t nTime) 

{ 

TimingDelay = nTime; 


while
(TimingDelay != 0); 

} 


/** 

* @brief Decrements the TimingDelay variable. 

* @param None 

* @retval None 

*/

void
TimingDelay_Decrement(
void
) 

{ 

if
(TimingDelay != 0x00) 

{ 

TimingDelay--; 

} 

}

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 June 23, 2013 at 20:36

A more appropriate cast would be

#define AVG_SLOPE ((float)(TS_CAL1 - TS_CAL2)/0) 

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..