cancel
Showing results for 
Search instead for 
Did you mean: 

temp LM75 got strange value

larsahl
Associate II
Posted on February 25, 2008 at 05:28

temp LM75 got strange value

#stm32-lm75-wrong-temp-value #lm75-stm32f103x-temp-register-s
4 REPLIES 4
larsahl
Associate II
Posted on May 17, 2011 at 12:24

Hello!

I got a problem with the LM75 tempsensor that are on the stm32 eval board.

When I read the temp value I got the result to 207 and that is 0xCF.

Seems a bit high something like 75 celcius degress.

And to get any value from it I need to read 2 times and the second time then I got results from it.

What can be wrong?

tta
Associate II
Posted on May 17, 2011 at 12:24

your adc is not configured correctly,

I think you have dual mode or injected channels ?

or DMA increase enabled ?

what board is it you talk about ?

quite alot of STM32 boards exist :)

ipathan1114
Associate II
Posted on May 26, 2015 at 14:01

stm32f103ze.. muc eval board....... i m getting temprature value as 74 degree..

just using muc and stlm75 temprature sensor... what is problem i can find out as i m new in embedded field.. plz help..

code file attached..

my code is below.....

#include ''stm32f10x.h''

#include ''stdio.h''

#define LM75_ADDR 0x90

void usart_send_char(unsigned char data)

{

while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

USART_SendData(USART1, data);

}

void SENDU(char *string)

{

while(*string!='\0')

{

usart_send_char(*string);

string++;

}

}

void init_usart1(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

USART_InitTypeDef USART_InitStructure;

/* Enalbe clock for USART1, AFIO */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1,ENABLE);

/***** tx and rx pin 9 and 10 of gpioa*****/

/* GPIOA PIN9 alternative function Tx */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* GPIOA PIN9 alternative function Rx */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* usart initilize*/

USART_DeInit(USART1);

USART_Cmd(USART1,ENABLE);

USART_InitStructure.USART_BaudRate =9600;

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_InitStructure.USART_Parity = USART_Parity_No ;

USART_InitStructure.USART_Mode = USART_Mode_Tx;

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

/* Configure USART1 */

USART_Init(USART1, &USART_InitStructure);

}

uint8_t LM75_Init() {

GPIO_InitTypeDef PORT;

I2C_InitTypeDef I2CInit;

/* Enable GPIO & I2C clocks */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB,ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

// GPIO_PinRemapConfig(GPIO_Remap_I2C1, ENABLE);

/* Configure I2C pins: SCL and SDA */

PORT.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;

PORT.GPIO_Mode = GPIO_Mode_AF_OD;

PORT.GPIO_Speed = GPIO_Speed_10MHz;

GPIO_Init(GPIOB,&PORT);

/* Configure PB.5 as Input pull-up, used as TemperatureSensor_INT */

PORT.GPIO_Pin = GPIO_Pin_5;

PORT.GPIO_Speed = GPIO_Speed_10MHz;

PORT.GPIO_Mode = GPIO_Mode_IPU;

GPIO_Init(GPIOB, &PORT);

/* I2C configuration */

I2C_DeInit(I2C1); // I2C reset to initial state

I2CInit.I2C_Mode = I2C_Mode_I2C; // I2C mode is I2C

I2CInit.I2C_DutyCycle = I2C_DutyCycle_2; // I2C fast mode duty cycle

I2CInit.I2C_OwnAddress1 = 0x00; // This device address (7-bit or 10-bit)

I2CInit.I2C_Ack = I2C_Ack_Enable; // Acknowledgment enable

I2CInit.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; // choose 7-bit address for acknowledgment

I2CInit.I2C_ClockSpeed = 200000;

I2C_Cmd(I2C1,ENABLE); // Enable I2C

I2C_Init(I2C1,&I2CInit); // Configure I2C

while (I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY)); // Wait until I2C free

return 0;

}

// Read 16-bit LM75 register

uint16_t LM75_ReadReg() {

uint16_t value;

// char str5[]=''abc.\n'';

//char str6[]=''def.\n'';

/*transmission--------------------------------------------------------------------*/

I2C_GenerateSTART(I2C1,ENABLE);

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT)); // Wait for EV5

I2C_Send7bitAddress(I2C1,LM75_ADDR,I2C_Direction_Transmitter); // Send slave address

//SENDU(str5);

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); // Wait for EV6

//SENDU(str6);

I2C_SendData(I2C1,0x00); // Send register address

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)); // Wait for EV8

/*-----------------reception-----------------------------------------------------------------*/

I2C_GenerateSTART(I2C1,ENABLE); // Send repeated START condition (aka Re-START)

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT)); // Wait for EV5

I2C_Send7bitAddress(I2C1,LM75_ADDR,I2C_Direction_Receiver); // Send slave address for READ

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)); // Wait for EV6

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_RECEIVED)); // Wait for EV7 (Byte received from slave)

value = (uint16_t)I2C_ReceiveData(I2C1)<<8 ; // Receive high byte

I2C_AcknowledgeConfig(I2C1,ENABLE); // enableI2C acknowledgment

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_RECEIVED)); // Wait for EV7 (Byte received from slave)

value |= I2C_ReceiveData(I2C1); // Receive low byte

I2C_AcknowledgeConfig(I2C1,DISABLE); // Disable I2C acknowledgment

I2C_GenerateSTOP(I2C1,ENABLE); // Send STOP condition

return value;

}

int main(void)

{

uint16_t temp;

//char str1[]=''\nSTM32F103ZET6 is online.\n'';

//char str2[]=''ready.\n'';

//char str3[]=''lm75 init fail.\n'';

//char str9[]=''out of reg conf .\n'';

char str4[]=''temp val is.hex..\n'';

char st[20];

SystemInit();

init_usart1();

//SENDU(str1);

if (!LM75_Init())

{

//SENDU(str2);

}

else

{

// SENDU(str3);

while(1);

}

SENDU(str4);

temp = LM75_ReadReg()>>7; //Temprature register address 0x00

sprintf(st,''temp=%d'',temp);

SENDU(st);

while(1);

}

________________

Attachments :

lm75_i2c.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0dV&d=%2Fa%2F0X0000000bbw%2FnuoCDsW6hI_FUkKFw3I7eIAPPxONCYtVrBd0vLWZl8Y&asPdf=false
ipathan1114
Associate II
Posted on May 26, 2015 at 14:03

stm32f103ze.. muc eval board....... i m getting temprature value as 74 degree..

just using muc and stlm75 temprature sensor... what is problem i can find out as i m new in embedded field.. plz help..

code file attached..

my code is below.....

#include ''stm32f10x.h''

#include ''stdio.h''

#define LM75_ADDR 0x90

void usart_send_char(unsigned char data)

{

while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

USART_SendData(USART1, data);

}

void SENDU(char *string)

{

while(*string!='\0')

{

usart_send_char(*string);

string++;

}

}

void init_usart1(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

USART_InitTypeDef USART_InitStructure;

/* Enalbe clock for USART1, AFIO */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1,ENABLE);

/***** tx and rx pin 9 and 10 of gpioa*****/

/* GPIOA PIN9 alternative function Tx */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* GPIOA PIN9 alternative function Rx */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* usart initilize*/

USART_DeInit(USART1);

USART_Cmd(USART1,ENABLE);

USART_InitStructure.USART_BaudRate =9600;

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_InitStructure.USART_Parity = USART_Parity_No ;

USART_InitStructure.USART_Mode = USART_Mode_Tx;

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

/* Configure USART1 */

USART_Init(USART1, &USART_InitStructure);

}

uint8_t LM75_Init() {

GPIO_InitTypeDef PORT;

I2C_InitTypeDef I2CInit;

/* Enable GPIO & I2C clocks */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB,ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

// GPIO_PinRemapConfig(GPIO_Remap_I2C1, ENABLE);

/* Configure I2C pins: SCL and SDA */

PORT.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;

PORT.GPIO_Mode = GPIO_Mode_AF_OD;

PORT.GPIO_Speed = GPIO_Speed_10MHz;

GPIO_Init(GPIOB,&PORT);

/* Configure PB.5 as Input pull-up, used as TemperatureSensor_INT */

PORT.GPIO_Pin = GPIO_Pin_5;

PORT.GPIO_Speed = GPIO_Speed_10MHz;

PORT.GPIO_Mode = GPIO_Mode_IPU;

GPIO_Init(GPIOB, &PORT);

/* I2C configuration */

I2C_DeInit(I2C1); // I2C reset to initial state

I2CInit.I2C_Mode = I2C_Mode_I2C; // I2C mode is I2C

I2CInit.I2C_DutyCycle = I2C_DutyCycle_2; // I2C fast mode duty cycle

I2CInit.I2C_OwnAddress1 = 0x00; // This device address (7-bit or 10-bit)

I2CInit.I2C_Ack = I2C_Ack_Enable; // Acknowledgment enable

I2CInit.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; // choose 7-bit address for acknowledgment

I2CInit.I2C_ClockSpeed = 200000;

I2C_Cmd(I2C1,ENABLE); // Enable I2C

I2C_Init(I2C1,&I2CInit); // Configure I2C

while (I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY)); // Wait until I2C free

return 0;

}

// Read 16-bit LM75 register

uint16_t LM75_ReadReg() {

uint16_t value;

// char str5[]=''abc.\n'';

//char str6[]=''def.\n'';

/*transmission--------------------------------------------------------------------*/

I2C_GenerateSTART(I2C1,ENABLE);

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT)); // Wait for EV5

I2C_Send7bitAddress(I2C1,LM75_ADDR,I2C_Direction_Transmitter); // Send slave address

//SENDU(str5);

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); // Wait for EV6

//SENDU(str6);

I2C_SendData(I2C1,0x00); // Send register address

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)); // Wait for EV8

/*-----------------reception-----------------------------------------------------------------*/

I2C_GenerateSTART(I2C1,ENABLE); // Send repeated START condition (aka Re-START)

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT)); // Wait for EV5

I2C_Send7bitAddress(I2C1,LM75_ADDR,I2C_Direction_Receiver); // Send slave address for READ

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)); // Wait for EV6

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_RECEIVED)); // Wait for EV7 (Byte received from slave)

value = (uint16_t)I2C_ReceiveData(I2C1)<<8 ; // Receive high byte

I2C_AcknowledgeConfig(I2C1,ENABLE); // enableI2C acknowledgment

while (!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_RECEIVED)); // Wait for EV7 (Byte received from slave)

value |= I2C_ReceiveData(I2C1); // Receive low byte

I2C_AcknowledgeConfig(I2C1,DISABLE); // Disable I2C acknowledgment

I2C_GenerateSTOP(I2C1,ENABLE); // Send STOP condition

return value;

}

int main(void)

{

uint16_t temp;

//char str1[]=''\nSTM32F103ZET6 is online.\n'';

//char str2[]=''ready.\n'';

//char str3[]=''lm75 init fail.\n'';

//char str9[]=''out of reg conf .\n'';

char str4[]=''temp val is.hex..\n'';

char st[20];

SystemInit();

init_usart1();

//SENDU(str1);

if (!LM75_Init())

{

//SENDU(str2);

}

else

{

// SENDU(str3);

while(1);

}

SENDU(str4);

temp = LM75_ReadReg()>>7; //Temprature register address 0x00

sprintf(st,''temp=%d'',temp);

SENDU(st);

while(1);

}

________________

Attachments :

lm75_i2c.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0eI&d=%2Fa%2F0X0000000bbt%2FaGWSKPWwUYJekNo16YRj1KE1wcbqvSs8H_U1UI8PwKo&asPdf=false