read temperature sensor


Closed Thread
Results 1 to 6 of 6
  1. #1
    breeno's Avatar
    breeno Guest

    Default read temperature sensor

    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

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

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

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    breeno's Avatar
    breeno Guest


    Did you find this post helpful? Yes | No

    Talking

    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

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

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

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    breeno's Avatar
    breeno Guest


    Did you find this post helpful? Yes | No

    Question

    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!

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

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

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Need a cheap touch sensor idea.. here it is
    By mister_e in forum Code Examples
    Replies: 20
    Last Post: - 16th April 2016, 22:42
  2. read temperature
    By breeno in forum General
    Replies: 16
    Last Post: - 6th October 2010, 12:55
  3. Cleaning up code
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2009, 07:14
  4. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  5. 18B20 temperature sensor and PIC
    By boban in forum Schematics
    Replies: 2
    Last Post: - 4th June 2007, 13:51

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts