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

TMP006 and pic 16f877a

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



Joined: 30 Apr 2018
Posts: 2

View user's profile Send private message

TMP006 and pic 16f877a
PostPosted: Tue May 01, 2018 2:43 pm     Reply with quote

I´m really lost in this problem, I´m just starting to work with ccs as you will notice and I haven´t found enough information to solve this issue. I´m using i2c with the TMP006, pic 16f877a and LCD 16x2, the tmp006 gives the temperature value in two bytes, I have read all the datasheet of this sensor but still haven´t resolved this issue. The thing is that the lectures shown in the LCD are not correct, at room temperature (28°C) the data variable, which must show the correct temperature value gives me a 1.96 °C. I print on the lcd the first byte , that show 255 and the second byte, that show 1.9, to try to understand where the problem was, evidently this two values are wrong too, any help will be strongly appreciated. Here is the code:
Code:

#include <16f877A.h>
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
#include <lcd.c>
#use delay(clock=4000000)



void main()
{
while(true){
lcd_init();
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

  BYTE datah;
   BYTE datal;
   float data;
   int dato;
 float div=32;
 float high,low;

 i2c_start();
 i2c_write(0x80);
  i2c_write(0x00);
   i2c_start();
   i2c_write(0x81);
  datah=i2c_read();       
  datal=i2c_read(0);   
   i2c_stop();
   dato=make16(datah,datal);
   dato= dato >> 2;
   data=dato;
   data=(float)data/(float)div;
high=data;
low=datal;
//printf(LCD_PUTC, "\f");// borrar lcd
  lcd_gotoxy(1,1);
 printf(LCD_PUTC," V: %3.2f", data);
 lcd_gotoxy(1,2);
 printf(LCD_PUTC," V: %3.2f", high); // I printed the first byte to check
  lcd_gotoxy(8,2);
 printf(LCD_PUTC," V: %3.2f", low); // I printed the second byte to check
 delay_ms(1000);
 printf(LCD_PUTC, "\f");
}
}
Embarassed
temtronic



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

View user's profile Send private message

PostPosted: Tue May 01, 2018 4:36 pm     Reply with quote

OK some comments
1) you should post a link to what 'TMP006' device you're using. I'm assuming it's a PCB module with a temperature sensor but we NEED to know EXACTLY what you have.

2) goto the code library and download PCM P's 'I2C scanner' program. Run it and confirm the TMPs address. Typically Arduino code is 7bit, CCS is 8 bit, so 80x 'could' be correct, but may not be depending on whoses PCB module you're using and if there are adrs jmprs available.

3) the sample code I downloaded was a lot more complicated than you show with corrections for die temperature.

Since I don't have a TMP006 here to test, I can't give you good,working code but take it in steps..
1) confirm the correct address
2) get the 2 bytes of data
3) manually 'do the math' to get the temperature
4) if the 'math' is correct, create the code, line by line. Don't try to do two or more operations in one line.
5) print the raw data in hex NOT floating point ! datah,datal,dato must be viewed as hex data. ALL conversions of these to floating point are useless.
The 'mathmatically' converted temperature can be viewed as a float (say 28.23 *C) ,this requires a format of %7.3F to display 123.456*C.

hopefully this will help and others may also have suggestions

Jay
JosCer



Joined: 30 Apr 2018
Posts: 2

View user's profile Send private message

PostPosted: Tue May 01, 2018 6:16 pm     Reply with quote

All right I will follow all your suggestions, and let you know if it works, the TMP i´m using is in this link http://www.ti.com/ww/eu/sensampbook/tmp006.pdf?DCMP=HPA_A8_sensampbook&HQS=TMP006-dt2-eu
temtronic



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

View user's profile Send private message

PostPosted: Tue May 01, 2018 8:27 pm     Reply with quote

OK, A quick read of the TMP006 datasheet:
#1 It's SMB bus compatible, so 3 volt device. Your PIC is a 5 volt device. Now you _may_ be able to use the SMB option but you'll have to read up about that. I2C != SMB . Also be sure to use the correct bus pullups.

#2 It appears the base address is 80x, so be sure the address jumpers are correct. The I2C scanner program will confirm. However you'll need to modify it slightly to actually be a SMB scanner.

#3 The datasheet does explain the steps needed to get the temperature. Simply choose the correct 'pointer' to the temperature register, read them, make a 16bit word, right shift twice, decide if + or - temp, then /32 to get *C of the reading. It seems simple enough but do each step in one line of code, think it through and compare your numbers to some of the examples they give. Hopefully the device defaults to a readable state as there are several 'configuration' bits that can be used. Again, read the datasheet.
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