Read and display Temperature from LM75

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Read and display Temperature from LM75

619 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by imroun1992 on Fri Sep 27 11:51:04 MST 2013
Hello,

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

#include <LPC43xx.h>                   
#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);
}
Labels (1)
0 Kudos
1 Reply

384 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bavarian on Mon Sep 30 04:28:20 MST 2013
The example included in KEIL µVision is fully doing the job:

.\Keil\ARM\Boards\Keil\MCB4300\Demo\

If you have the evaluation version of µVision, then please compile with _EVAL_VERSION_ to meet the code size restriction.
Then you can step through the code an see how the I2C interface is set up and how the temperature data from LM75A is read.

Regards,
NXP Support.
0 Kudos