Need help for reading I2C Sensor


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Mar 2008
    Location
    Switzerland
    Posts
    7

    Red face Need help for reading I2C Sensor

    Hello *

    This is my first time i do somthing with I2C. I tray to read a digital pressure transducers from Sensor Technics. I use the CSDX Series.


    the code is:

    I2C_data var PORTB.1 ' I2C Daten Leitung
    I2C_clock var PORTA.4 ' I2C Clock Leitung



    Main:


    I2CRead I2C_data,I2C_clock,$F1,0,druck,druck2 ' Read string from slave
    Pause 10

    lcdout $FE,$D4,"Druck ",dec druck, "mbar" ,dec druck2'

    pause 10

    goto main


    on the display nothing is changing.


    Thanks for your help.


    Rolf





    The Data Sheet is under :

    http://www.sensortechnics.com/index....91f3ec91b908bd
    Attached Images Attached Images

  2. #2
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251

    Default

    Try this!!
    I2CRead I2C_data,I2C_clock,$F1,0,[druck,druck2]
    Manual page 82-85
    And I hope you did'n forget the pullup resistors for the i2c lines
    Last edited by mat janssen; - 31st May 2008 at 18:15.

  3. #3
    skimask's Avatar
    skimask Guest

    Default

    Or even if the circuit is operating or not in the first place...heartbeat LED...

  4. #4
    Join Date
    Mar 2008
    Location
    Switzerland
    Posts
    7

    Default Thank for your Input

    I will tray out the new code on Monday. Can you tell me for what is the [ ] ?
    The Pull Up resistors are on the board.

    Thanks
    Last edited by Omalik; - 1st June 2008 at 18:17.

  5. #5
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Omalik View Post
    I will tray out the new code on Monday. Can you tell me for what is the [ ] ?
    It's in the manual...

  6. #6
    Join Date
    Jan 2006
    Location
    Toronto
    Posts
    109

    Default

    Here is an example of how I use I2C with an EEPROM and the I/O Expander, I hope it helps.



    DEFINE I2C_HOLD 1

    Address VAR WORD
    SCL VAR PORTC.3 ' I2C Clock pin
    SDA VAR PORTC.4 ' I2C Data pin

    Address = 0



    '------------------------------------------------------------------------------------------------
    ' Read Password from EEPROM
    '------------------------------------------------------------------------------------------------
    ReadPassword:
    Address = 0
    I2CREAD SDA,SCL,$A0,Address,[Password[1],Password[2],Password[3],Password[4]]
    Return
    '------------------------------------------------------------------------------------------------



    '------------------------------------------------------------------------------------------------
    ' Save Password to EEPROM
    '------------------------------------------------------------------------------------------------
    SavePassword:
    Address = 0
    I2CWRITE SDA,SCL,$A0,Address,[Password[1],Password[2],Password[3],Password[4]]
    Return
    '------------------------------------------------------------------------------------------------



    '------------------------------------------------------------------------------------------------
    ' Subroutine to handle I2C errors
    '------------------------------------------------------------------------------------------------
    I2CError:
    LCDOut $fe,1
    LCDOut $fe,2, "I2C Bus Timed Out" ' I2C command timed out
    Pause 1000

    GoTo loop
    '------------------------------------------------------------------------------------------------



    '------------------------------------------------------------------------------------------------
    ' Setup I2C I/O Expander
    '------------------------------------------------------------------------------------------------
    SetupIOExpander:
    '*** Setup I/O Expander PortA as Output, PortB as Input ***
    I2CWrite SDA,SCL,$40,[6,0,31], I2CError
    Pause 150

    '*** Set the Interrupt Capture Rate to Fast ***
    'I2CWrite SDA,SCL,$40,[11,1], I2CError
    'Pause 150

    '*** Set I/O Expander PortA Outputs to LOW ***
    I2CWrite SDA,SCL,$40,[0,0], I2CError
    Pause 150

    RESUME
    '------------------------------------------------------------------------------------------------


  7. #7
    Join Date
    Mar 2008
    Location
    Switzerland
    Posts
    7

    Default

    I tray out

    I2CRead I2C_data,I2C_clock,$F1,0,[druck,druck2]

    but it does not work at all. I find a lot of examples for Eeprom but not one for the sensor I use.

    does some have any idea ?

    Thanks

  8. #8
    Join Date
    Jan 2006
    Location
    Toronto
    Posts
    109

    Default

    Quote Originally Posted by Omalik View Post
    I tray out

    I2CRead I2C_data,I2C_clock,$F1,0,[druck,druck2]

    but it does not work at all. I find a lot of examples for Eeprom but not one for the sensor I use.

    does some have any idea ?

    Thanks
    From what I can see in the data sheet you should be using this:

    I2CRead I2C_data,I2C_clock,$F1,[druck,druck2]

    I don't know what the 0 you had there was for but the R/W bit is set by the I2CRead/I2CWrite command, you don't need to set it.

    also check what you have druck and druck2 declared as, byte or word.

  9. #9
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by PJALM View Post
    From what I can see in the data sheet you should be using this:
    I2CRead I2C_data,I2C_clock,$F1,[druck,druck2]
    I don't know what the 0 you had there was for but the R/W bit is set by the I2CRead/I2CWrite command, you don't need to set it.
    Probably should be using $F0 instead of $F1 also.

  10. #10
    Join Date
    Mar 2008
    Location
    Switzerland
    Posts
    7

    Default

    i did a picture on the KO.
    blue is clock and red are data.

    and i can not read the sensor.
    Attached Images Attached Images   
    Last edited by Omalik; - 8th June 2008 at 18:46.

  11. #11
    Join Date
    Mar 2008
    Location
    Switzerland
    Posts
    7

    Default

    Quote Originally Posted by skimask View Post
    Probably should be using $F0 instead of $F1 also.

    see datasheet
    Attached Images Attached Images  

  12. #12
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Omalik View Post
    see datasheet
    Right...and PBP handles the R/W bit for you...as stated a few posts above.

  13. #13
    Join Date
    Mar 2008
    Location
    Switzerland
    Posts
    7

    Default

    Now the sensor is working well

    Thanks for all your help

    The code I use is:



    I2CRead I2C_data,I2C_clock,$F1,[druck]

    an to calculate the mbar:

    IF druck > 1999 then ' nur positive Druck auswerten

    druck = ((druck - 2000) * 6) + ((druck - 2000) /4) ' * 25 / 100

    else
    druck = 0

    endif
    see also the printscreen from the I2C bus.
    Attached Images Attached Images  

  14. #14
    Join Date
    Jan 2006
    Location
    Toronto
    Posts
    109

    Default

    I am glad to see that you got it working

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, 23:42
  2. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 23:31
  3. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 22:07
  4. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 20:33
  5. Using a TC74A0 with PBP(Thermal sensor via I2C)
    By navaismo in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st November 2006, 19:25

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