PDA

View Full Version : read temperature sensor



breeno
- 6th January 2005, 00:11
I want to read temperature from an MCP9800 temperature sensor, which is i2c compatible.

I know the device address and the temperature register address

i would like to know whic is the right i2cread instruction to read the temperature...

i tried

i2cread sda,scl,dev_addr,reg_addr,[var]

but it doesn't work!!!

any idea?

thanks a lot

mister_e
- 7th January 2005, 19:21
there's maybe many reason why it doesn't work


i2cread sda,scl,dev_addr,reg_addr,[var]

1. what are your definition of these var (SDA,SCL,DEV_ADDR,REGADDR,VAR) ?

Is at least dev_addr is a byte loaded with %1001000

are SDA,SCL pin are pull-up with 4.7 K resistors?

wich device (PIC) are you using ?

There's maybe some register you need to set before the device work properly too. The best solution...again, datasheet. I know it's pain in the neck as solution but there's no other way exept if somebody here has already work with those sensor and have some code to share...

Have you some I2C based EEPROM (24c01, 24c02... ) to test with before the temperature sensor??? This could be handy to know how to work with simple I2C device before using *a bit* more complicated ones.

breeno
- 8th January 2005, 01:01
Reading the datasheet i know that

the device address (DEV_ADDR) is %1001000b, where b is set for read and clear for write (i leave the bit set)

the temperature register is accessed by a pointer; the temperature register address is %00000000 (REG_ADDR)

the sda and scl pins are pulled-up by two 5k6 resistors

so i tried the instruction
i2cread sda,scl,%10010001,%00000000,[var],NOCONNECT

but the noconnect code is always executed, also changing the DEV_ADDR...... i don't know why.......!!!!!!!!!!

Thanks a lot for the help

mister_e
- 9th January 2005, 13:12
try it exactly like this
a var byte
b var byte
c var byte

a=%10010001
b=%00000000
i2cread sda,scl,a,b,[c],NOCONNECT

what about now? in case nothing is working, be sure that the pins you're using from the PIC are set to digital and they are bidirectionnal : input and output.

Tell us which pic you're using and which pins are connected to sensor.

Also be sure that scl and sda are not reverted.

breeno
- 10th January 2005, 00:00
nothing to do, always no connection

i use a 16f84a.... pin connections are correct and sda scl are not inverted....sda is connected to RA4 while scl is connected to RA3...

the syntax semms to be correct, but it doesn't work! why?

Thank you for help!

mister_e
- 10th January 2005, 07:04
RA4 is an open drain when output but it'S not suppoose to give you any kind of shit while you're using Pull-ups. what about if you try on portB... sure it will do the same. In this case there's really something to initialize before the sensor works.