This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I2C AND Thermometer LM75

Hello,

I am trying to read the temperature from LM75 Thermometer, I use KEIL MCB4357 Development Board.The program is :

#include <br> #include "LED.h"
#include "KBD.h"
#include "GLCD.h"
#include "TH_LM75.h"
#include "I2C.h"

#define KEY_P4_0 1
#define KEY_P4_3 2
#define KEY_P4_4 4
#define KEY_WAKEUP 8

#define Font1 1
#define Font0 0

#define TH_I2C_ADDR 0x48
#define REG_TEMP 0x00
#define REG_CONF 0x01
#define REG_THYS 0x02
#define REG_TOS 0x03

int main (void) {

LED_Init();
KBD_Init ();
GLCD_Init();
TH_Init();
I2C_Init();

LED_Val(0x55);

GLCD_Clear (White);
GLCD_SetBackColor (Blue);
GLCD_SetTextColor (White);
GLCD_DisplayString (0, 0, 1, " IUT CACHAN GEII2 ");
GLCD_DisplayString (1, 0, 1, " Projet Quadricoptère ");
GLCD_SetBackColor (White);
GLCD_SetTextColor (Blue);

while (1) {
if (KBD_GetKeys() & KEY_P4_0)
{ LED_On(1);
GLCD_SetTextColor(Black);
} else
{ LED_Off(1);
GLCD_SetTextColor(LightGrey);
} GLCD_DisplayString (4, 9, 1, "P4_0");

if (KBD_GetKeys() & KEY_P4_3)
{ LED_On(2);
GLCD_SetTextColor(Black);
} else
{ LED_Off(2);
GLCD_SetTextColor(LightGrey);
} GLCD_DisplayString (4, 14, 1, "P4_3");

if (KBD_GetKeys() & KEY_P4_4)
{ LED_On(3);
GLCD_SetTextColor(Black);
} else
{ LED_Off(3);
GLCD_SetTextColor(LightGrey);
} GLCD_DisplayString (5, 9, 1, "P4_4");

if (KBD_GetKeys() & KEY_WAKEUP)
LED_On(4);
else
LED_Off(4);

TH_GetTemp(&Temp);
} }

And finally i try to call this function but i don't know can i call, and anyone to help me to activate I2C for reading temperature :

uint16_t TH_GetTemp (TH_DATA *ThDat) {
uint8_t val[2];

if (I2C_RdData (TH_I2C_ADDR, REG_TEMP, val, 2) == 0) {
ThDat->Temp = (val[0] << 8) | (val[1] & 0x80) ;
return (0);
} return (1);
}