CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

Problem with LM75A NXP [Solved]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
qwwe



Joined: 17 Sep 2017
Posts: 56

View user's profile Send private message

Problem with LM75A NXP [Solved]
PostPosted: Sun Jan 21, 2018 2:09 pm     Reply with quote

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.
PCM programmer



Joined: 06 Sep 2003
Posts: 20139

View user's profile Send private message

PostPosted: Sun Jan 21, 2018 2:49 pm     Reply with quote

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.
temtronic



Joined: 01 Jul 2010
Posts: 5830
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 21, 2018 3:28 pm     Reply with quote

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.
qwwe



Joined: 17 Sep 2017
Posts: 56

View user's profile Send private message

PostPosted: Sun Jan 21, 2018 11:39 pm     Reply with quote

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?
qwwe



Joined: 17 Sep 2017
Posts: 56

View user's profile Send private message

PostPosted: Mon Jan 22, 2018 12:40 am     Reply with quote

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.
qwwe



Joined: 17 Sep 2017
Posts: 56

View user's profile Send private message

PostPosted: Mon Jan 22, 2018 1:19 am     Reply with quote

problem solved .
In fact, I had forgotten to connect the lines of the address to the ground
Thankful
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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