![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
qwwe
Joined: 17 Sep 2017 Posts: 59
|
Problem with LM75A NXP [Solved] |
Posted: Sun Jan 21, 2018 2:09 pm |
|
|
Hello
I wrote a program for the lm75 sensor that works well in Proteus software.
But when it is in practice, the temperature displayed on the lcd some times jumps from the actual temperature to -1.
Where do you think the program is having trouble?
The sensor used is lm75 of nxp.
The display lcd nokia5110.
In practice, like the following circuit:
Code: |
#include <16f1829.h>
#device *=16
#fuses HS //High speed Osc (> 4mhz for PCM/PCH)
#fuses NOWDT //NO Watch Dog Timer
#fuses PUT //Power Up Timer
#fuses NOLVP //No low v
#fuses NOCPD //No EE protection
#fuses NOPROTECT //Code not protected from reading
#fuses NOWRT //Program memory not write protected
#fuses NODEBUG //No Debug mode for ICD
#fuses NOBROWNOUT //No brownout reset
#USE DELAY (crystal=11059200)
#use i2c(master,sda=PIN_B4, scl=PIN_B6,FORCE_HW,I2C1)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <Nokia_5110.c>
signed long read_full_temp();
void clear_temp();
char c[]="TEMP:";
signed int16 t;
char temp[7];
int r;
void main()
{
nokia_init();
nokia_contrast(100);
while(true)
{
delay_ms(200);
t=0;
clear_temp();
nokia_clean_buffer();
nokia_gotoxy(5,1);
nokia_printstr(c);
delay_ms(1);
t= read_full_temp();
itoa(t,10,temp);
nokia_gotoxy(35,1);
nokia_printstr(temp);
nokia_gotoxy(70,1);
nokia_printchar('$');
nokia_printchar('C');
nokia_box(0,0,83,47,0,1);
nokia_bar(0,20,83,20,1,1);
nokia_refresh();
}
}
////////////////////////////////////////////////////////////////////////
signed long read_full_temp() {
signed long datah, datal;
signed long data;
i2c_start();
i2c_write(0x90);
i2c_write(0x00);
i2c_start();
i2c_write(0x91);
datah=i2c_read(1);
datal=i2c_read(0);
i2c_stop();
data=datah;
if(bit_test(datah,7)==1)
{
data=data-256;
}
return(data);
}
void clear_temp()
{
for(r=0;r<=7;r++)
{
temp[r]='\0';
}
}
|
The temperature part does not matter to me.
Thanks for help. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 21, 2018 2:49 pm |
|
|
Your driver is substantially different from the CCS driver: lm75cim3.c
I suggest you look at the CCS driver and use it instead of your code. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Sun Jan 21, 2018 3:28 pm |
|
|
2 comments
1) Noise could be coming into the device. Be sure Vdd is stable and noise free. The Maxim datasheet suggests 5K in series with SCL, SDA lines suggesting board layout is critical.
2) The 'temp part' of your code could be a problem. You've got 2 8-bit variables from the device that need to be merged into the proper bits and then displayed. If you don't 'cast' correctly you'll end up with bad numbers. |
|
![](templates/subSilver/images/spacer.gif) |
qwwe
Joined: 17 Sep 2017 Posts: 59
|
|
Posted: Sun Jan 21, 2018 11:39 pm |
|
|
I got an idea from lm75cim3.c to write this Program .
When I used exactly my own lm75cim3.c, I did not show the correct temperature, for example, -1 was 225.
That's why I applied the above changes to the program.
This program responds correctly to proteus, but not in practice.
Is the lm75 sensor from nxp different from other lm75 sensors? |
|
![](templates/subSilver/images/spacer.gif) |
qwwe
Joined: 17 Sep 2017 Posts: 59
|
|
Posted: Mon Jan 22, 2018 12:40 am |
|
|
I also used this driver lm75cim3.c like before, just this time it jumps from the actual temperature to 255.
Because, as I said, this driver does not show a negative. |
|
![](templates/subSilver/images/spacer.gif) |
qwwe
Joined: 17 Sep 2017 Posts: 59
|
|
Posted: Mon Jan 22, 2018 1:19 am |
|
|
problem solved .
In fact, I had forgotten to connect the lines of the address to the ground
Thankful |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|