Sensirion SHT11 with a PIC16F628-20


View Poll Results: Have I included enough relevant material to make the problem clear?

Voters
1. You may not vote on this poll
  • YES. I see what you mean

    0 0%
  • COULD BE BETTER: Kind of understand what your trying to say

    1 100.00%
  • NO: What the heck are you talking about

    0 0%
Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    gbm_designs's Avatar
    gbm_designs Guest

    Default Sensirion SHT11 with a PIC16F628-20

    Greetings-

    I 've recently moved from the BS2 to the PIC Basic Compiler Pro software.


    I'm trying to attach a Sensirion SHT11 Temperature and Humidity sensor to the Pic 16F628-20 and then send the Calculated values in Celcius and Farenheit, as well as Relative Humidity %RH to the COM1 port on my windows machine.

    I have found many sample source code, but none seem to work for me when I compile. Either written for a separate compiler, or a different chip, so the #Include statements are wrong.

    Can anyone help me along here? I would really appreciate it.

    If any other information is required, please let me know.


    Thank you,

    Christian
    EPIC PROGRAMMER
    PIC BASIC COMPILER PRO
    16F628-20
    20-MHz External Xtal

  2. #2
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    attached is a working piece of code for the 16F628

    Code:
    ___________________
    
    ' Temperature, Relative Humidity and Dewpoint
    ' Processor : 16F628
    ' Sensor    : SHT1x / SHT7x
    ' Display   : 16x2
    
    '** Pin-Assingments
    
    dta     VAR PORTB.1     ' Sensor Data
    clk     VAR PORTB.0     ' Sensor Clock
    
    '** Constants
    
    cmdtr     CON %00000011    ' Command "read temperature"
    cmdhr     CON %00000101    ' Command "read humitity"
    
    '** Variables
    
    result     VAR WORD    ' RAW Data from Sensor
    chksum     VAR BYTE     ' Checksum
    cmd     VAR WORD    ' Sensor Command
    RHlin     VAR WORD    ' Rel. Humidity (RH) Linear (% *10)
    RHtc    VAR WORD    ' Rel. Humidity (RH) temp. compensated (% *10)
    Temp     VAR WORD    ' Temperature (°C *100)
    DP     VAR WORD    ' Dewpiont (°C *10)
    
    
    '** Temp variables used in div. calculations
    
    TempDP  VAR WORD
    Rchk     VAR BYTE 
    logEW     VAR WORD
    sign     VAR BIT
    wy        VAR WORD
    wz        VAR WORD
    wj        VAR WORD
    wx      VAR WORD
    i     VAR BYTE
    ix     VAR BYTE
    bt     VAR BIT
    
    
    Pause 500
    LCDOut $FE,1,"**   SHT 11   **"
    PAUSE 1000
    
    main:
    
    GoSub init
    cmd = cmdtr
    
    GoSub readsensor
    Temp=result-3995
    
    GoSub init
    cmd = cmdhr
    
    GoSub readsensor
    RHlin=(26542-(54722**result+result))**result-40  ' RH linear
    RHtc=655+(result*5)+(result**15917)                 
    RHtc=(RHtc**(Temp/10+2480))-(RHtc**2730)+RHlin   ' RH temp. compensated
    
    GoSub dewpoint
    
    LCDOut $FE,$80," ",$DF,"C","   ",$25,"RH","    DP "
    LCDOut $FE,$C0,DEC2 (TEMP/100),".",DEC1 (temp/10),"  ",DEC2 RHTC/10,".",DEC1 RHTC,"  ",DEC2 ABS DP/10,".",DEC1 ABS dp
    sleep 10
    GoTo main
    
    '** Init Sensor
    init:                                             
    High dta 
    Low clk 
    For i=1 to 10 
    High clk
    Pause 1 
    Low clk
    Pause 1 
    Next i 
    Call tstart 
    Return 
    
    '** start transfer
    tstart:
    High clk
    Pause 1 
    Low dta 
    Pause 1 
    Low clk
    Pause 1 
    High clk
    Pause 1 
    High dta 
    Pause 1 
    Low clk
    Return 
    
    '** get Data from Sensor
    readsensor:
    GoSub tstart
    GoSub WaitSensor
    
    ShiftOut dta,clk,1,[cmd\8]                  ' send command
    Input dta                      ' wait acknowledge 
    Low clk
    While dta=1 
    Wend
    PulsOut clk,10                      ' send ack 
    While dta=0 
    Wend
    While dta=1                      ' wait for conversion to complete
    Wend 
    Low clk
    ShiftIn dta,clk,0,[result.highbyte\8]          ' get first byte
    Low dta 
    PulsOut clk,10                      ' send ack 
    ShiftIn dta,clk,0,[result.lowbyte\8]             ' get second byte
    Low dta 
    PulsOut clk,10                      ' send ack 
    ShiftIn dta,clk,0,[chksum\8]                     ' get third byte (checksum)
    High dta 
    PulsOut clk,10                      ' send ack 
    Input dta                      ' End of Transmission
    Input clk                          
    
    Return
    
    '** Dewpoint Calculation
        ' See: SENSIRION Application Note "Dewpoint Calculation"
        ' logEW = (0.66077+7.5*T/(237.3+T)+(log(RH)-2)
          ' DP = ((0.66077-logEW)*237.3)/(logEW-8.16077)
    
    DewPoint:
      
      TempDP=Temp/10
      logEW=6608
      sign=TempDP.bit15
      wz=ABS TempDP
      wx=(7*wz)+(wz/2)                              
      wy=2373+wz
      wj=wx/wy
       For ix=15 to 0 step -1
        wx=(wx//wy)<<1
        wz.bit0(ix)=wx/wy
       Next
      wx=(-sign^((wj*10000)+(wz**10000)))+sign        
      logEW=wx+logEW
      wx=RHtc
      wj=(NCD wx) - 1
      wx=wx<<(15-wj)
      wz=0
      For ix=14 to 0 step -1
        wy=wx**wx
        wz.bit0(ix)=wy.bit15
        bt=~wy.bit15
        wx=(wy<<bt)+(bt && wx.bit15)
       Next
      
      wx=((wj*4000)**49321)+(wz**6021)
      logEW=wx+logEW-30000            
      sign=logEW.bit15
      logEW=(-sign^(((ABS logEW)+2)/4))+sign
      wx=1652-logEW
      sign=~wx.bit15
      wx=ABS wx
      wy=20402-logEW
      wj=wx/wy
      
       For ix=15 to 0 step -1
        wx=(wx//wy)<<1
        wz.bit0(ix)=wx/wy
       Next
      
      DP=((23730**wz)+5)/10
      DP=(-sign^DP)+sign
    
    Return
    
    WaitSensor:
      result=4096
    Loop:
      result=result-1
       IF dta && result.bit11 Then Loop
      Return
    End
    ___________________

    Regards

    Ralph
    Last edited by ScaleRobotics; - 6th April 2011 at 15:24. Reason: added code tags

  3. #3
    gbm_designs's Avatar
    gbm_designs Guest


    Did you find this post helpful? Yes | No

    Question Compile Error with PBCP

    Greetings Ralph-

    Thank you for your help.

    PROBLEMS:

    PROBLEM1.
    I get a COMPILE ERROR in this Section of Code:

    DewPoint:

    For ix=14 to 0 step -1
    wy=wx**wx
    wz.bit0(ix)=wy.bit15
    bt=~wy.bit15
    wx=(wy< Next <<<<---------THIS IS THE PROBLEM


    QUESTION: Can you let me know what's missing here?

    ************************
    PROBLEM2:
    After COMMENTING out the ERROR LINE is PROB1, I set up the circuit as described below ((SEE CIRCUIT SPECS)) and use Hyperterminal to view the Output of the Program by COMMENTING out the LCD output in your code and replacing it with the following:

    SerOut2 PORTB.2,86,[DEC2 (TEMP/100),".",DEC1 (temp/10)," ",DEC2 (TEMP/100),".",DEC1 (temp/10)," ",DEC2 RHTC/10,".",DEC1 RHTC," ",DEC2 ABS DP/10,".",DEC1 ABS dp,13,10]
    'LCDOut $FE,$C0,DEC2 (TEMP/100),".",DEC1 (temp/10)," ",DEC2 RHTC/10,".",DEC1 RHTC," ",DEC2 ABS DP/10,".",DEC1 ABS dp


    WHAT HAPPENS: I get the SAME Values over and over again

    ** SHT 11 **
    12.8 00.4 12.3
    12.8 12.8 00.4 12.3

    QUESTION: ANY IDEAS?

    ************************

    CIRCUIT SPECS:

    PIC16F628-20
    PINOUTS
    4-----MCLR---4.7kohm to 5vdc
    5-----VSS-----GND
    6-----RB0-----Pin3 of SHT11 (SCK)
    7-----RB1-----Pin2 of SHT11 (Data)
    8-----RB2-----Pin10 of MAX232 (T2IN)
    15---OSC2---XTAL (4Mhz)
    16---OSC1---XTAL (4Mhz)


    SHT11
    PINOUTS
    1----GND----GND
    2----DATA---Pin7 of PIC (RB1)
    3----SCK --- Pin6 of PIC (RB0)
    4----VDD----5VDC


    THANKS,

    I hope this description is complete enough

    CHRISTIAN

  4. #4
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Christian,

    initially I tried to post the example using " [ code ] ... [ /code ] "

    when I viewed my posting I had to realize the code was truncated at some point.

    I have edited my posting and the full code is now there as plain ASCII.

    please reload the code.

    regards

    Ralph

  5. #5
    gbm_designs's Avatar
    gbm_designs Guest


    Did you find this post helpful? Yes | No

    Question Code looks the same

    Greetings Ralph-

    It appears that the source code is the same.

    I did a quick line comparison and the same number of characters are present.

    Could you e-mail it to me?

    Thank you

    mailto: [email protected]


    Christian

  6. #6
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default Re: Code looks the same

    . . .Could you e-mail it to me?
    DONE!

  7. #7
    gbm_designs's Avatar
    gbm_designs Guest


    Did you find this post helpful? Yes | No

    Default Got the E-mail

    Greetings Ralph-

    Thank you for the E-mail.

    I used the new code with my changes for the Serial Port, rather than LCD.

    However I still get the same value over and over.

    ** SHT 11 **
    RH DP •
    12.8 12.8 00.4 14.9


    RH DP •
    12.8 12.8 00.4 14.9


    Kind of odd.


    I re-tested this SHT11 Device with my BS2 Program and hardware and it works fine.

    I have GOT to be doing something WRONG.



    Christian

  8. #8
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Christian,

    I'll have a look at it tomorrow morning when I'm back at my desk.

    regards

    Ralph

  9. #9
    gbm_designs's Avatar
    gbm_designs Guest


    Did you find this post helpful? Yes | No

    Default THANKS!

    I'll keep banging away at it tonight also.



    I'll let you know what I find.


    Christian

  10. #10
    Join Date
    Nov 2004
    Location
    malawi
    Posts
    11


    Did you find this post helpful? Yes | No

    Default Need help also

    hi! iam also working SHT11 project with PIC16F877 display with LCD, itry Ralph source code but, only **SHT 11** display no sensor reading ,can someone email source code to me? [email protected]
    thanks

  11. #11
    Join Date
    Aug 2005
    Location
    Ontario, Canada
    Posts
    5


    Did you find this post helpful? Yes | No

    Thumbs up Missing part of code SHT11

    For anyone trying to get this first off, add wx=wy<< bt+(bt & wx.bit15)
    instead of the truncated part Christian had indicated.
    (nice work on the code Ralph)
    This works fine on a PIC16F876A 20mhz using portc.3 and portc.4
    I can see why Ralph had problems with it not posting properly. I had to
    put in a space before the first bt to see it properly as without the space
    it was truncating my reply too. Anyone else have a problem posting code
    like this?
    (helps to look at the preview)
    Hope this helps someone.
    Ron

  12. #12
    Join Date
    Mar 2007
    Posts
    5


    Did you find this post helpful? Yes | No

    Unhappy Please help me ??????

    I have been trying to get this code to work for the last week,A friend and i have both recived samples and have been unable to get the project going after overcoming the first compile error it seems that the device wont respond and it just hangs in the readsensor routine, Could yoiu please post the working picbasic pro or email it to me at [email protected].
    it seems that if i force data line to go low by shorting to ground the code execution continues and outputs repative numbers.
    There is a misplaced next could you please clarafy where this is ment to go

    regards Evolution

  13. #13
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Angry Sometimes I feel tired ... but why ????

    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  14. #14
    Original's Avatar
    Original Guest


    Did you find this post helpful? Yes | No

    Default

    Look at this:
    Code:
    '*******************************[ SHT11 Sample Code ]********************************
    ' File...... SHT11.bas
    ' Purpose... SHT11 digital humidity sensor sample code
    ' MCU....... Microchip PIC16F877
    ' Software.. Converted to Proton+ 2.0 from PBPro ver 2.4
    ' Author.... Brandon Tarr
    ' E-Mail.... [email protected]
    ' Web....... http://www.spectrumedix.com
    ' Started... May 15, 2002
    ' Updated... 
    ' Version... 1.0                                               
    '**************************************************************************
    
     device 16f877
    
    DEFINE xtal 4
    Define  LCD_DREG        PORTD
    Define  LCD_DBIT        4
    Define  LCD_RSREG       PORTE
    Define  LCD_RSBIT       0
    Define  LCD_EREG        PORTE
    Define  LCD_EBIT        1
    
    TEMP            con     1
    HUMI            con     2
                                            ' adr   command r/w
    Symbol statusregw      =     $06             ' 000   0011    0
    Symbol statusregr      =     $07             ' 000   0011    1
    Symbol measuretemp     =     $03             ' 000   0001    1
    Symbol measurehumi     =     $05             ' 000   0010    1
    Symbol resett           =     $1e             ' 000   1111    0
    
    ' -----[ Variables ]---------------------------------------------------------------------
    Dim SCK         as     PORTC.3             ' SHT11 SCK
    Dim SDATA       as     PORTC.4             ' SHT11 DATA
    
    Dim i           as     byte
    Dim f           as     byte
    Dim value       as     byte
    Dim errorr       as     bit
    Dim mode        as     byte
    Dim ack         as     bit
    
    Dim vall         as     byte
    Dim pktvalue    as     word
    Dim pktchksum   as     byte
    
    Dim humival     as     word
    Dim tempval     as     word
    Dim dewpoint    as     byte
    Dim checksum    as     byte
    
    ' -----[ Initialization ]----------------------------------------------------------------
    ADCON1 = 7              ' Set PORTA and PORTE to digital
    Low PORTE.2             ' LCD R/W line low (W)
    Pause 100               ' Wait for LCD to start
    lcdout $fe, 1
    
    ' -----[ Main Code ]---------------------------------------------------------------------
    usetheSHT11:
    gosub connectionreset
    value = measurehumi
    gosub measure                                        ' measure humidity
    humival = pktvalue * 1000
    humival = DIV32 4095
    lcdout $fe, 2, "                    ", $fe, 2, "Humidity: ", dec humival / 10, ".", dec humival // 10, "%"
    value = measuretemp
    gosub measure                                        ' measure temperature
    tempval = pktvalue * 1000
    tempval = DIV32 16383
    lcdout $fe, $c0, "                    ", $fe, $c0, "Temperature: ", dec tempval / 10, ".", dec tempval // 10, 223, "C"
    pause 100                                            ' decrease sample time
    goto usetheSHT11
    
    ' -----[ Subroutines ]-------------------------------------------------------------------
    connectionreset:            
    ' communication reset: DATA line is high and at least 9 SCK cycles followed by transstart
    '         ________________________________________       _____
    ' SDATA:                                          |_____|
    '           _   _   _   _   _   _   _   _   _     __    __
    '   SCK:  _| |_| |_| |_| |_| |_| |_| |_| |_| |___|  |__|  |___
    high SDATA
    low SCK                                 ' set initial state
    for i = 1 to 9                          ' 9 SCK cycles
        high SCK
        low SCK
    next
    gosub transstart                       ' transmission start
    return
    
    transstart:                             
    ' generates a transmission start 
    '         ___       _____
    ' SDATA:     |_____|
    '            __    __
    '   SCK:  __|  |__|  |___
    
    high SDATA
    low SCK                                 ' set initial state
    high SCK
    low SDATA
    low SCK
    high SCK
    high SDATA
    low SCK
    return
    
    measure:
    ' makes a measurement (humidity/temperature) with checksum
    errorr = 0
    gosub transstart                        ' transmission start
    gosub writebyte
    for i = 1 to 255                        ' wait until sensor has finished the measurement
        if SDATA = 0 then
            goto meascomplete
        endif
        pause 1
    next 
    meascomplete:
    if SDATA != 0 then                      ' or timeout (~2 sec.) is reached
        errorr = 1
    endif
    ack = 1
    gosub readbyte                          ' read the first byte (MSB)
    pktvalue.highbyte = vall
    gosub readbyte                          ' read the second byte (LSB)
    pktvalue.lowbyte = vall
    ack = 0
    gosub readbyte                          ' read checksum (no acknowledge to put sensor in "sleep" mode)
    pktchksum = vall
    return
    
    writebyte:
    ' writes a byte on the Sensibus and checks the acknowledge
    errorr = 0
    i = $80
    while i > 0
        if (i & value) != 0 then              ' masking value with i
            high SDATA                        ' write to SENSI-BUS
        else
            low SDATA
        endif
        high SCK                            ' clk for SENSI-BUS
        low SCK
        i = i / 2                           ' shift bit for masking
    wend
    high SDATA                              
    TRISC.4 = 1                             ' release SDATA-line
    high SCK                                ' clk #9 for ack
    errorr = SDATA                           ' check ack (SDATA will be pulled down by SHTXX)
    low SCK
    return
    
    readbyte:
    ' reads a byte from the Sensibus and gives an acknowledge in case of "ack=1"
    vall = 0
    high SDATA                              
    TRISC.4 = 1                             ' release SDATA-line
    i = $80
    while i > 0
        high SCK                            ' clk for SENSI-BUS
        if SDATA = 1 then                   ' read bit
            vall = vall | i
        endif
        low SCK
        i = i / 2
    wend
    TRISC.4 = 0                             ' grab SDATA-line
    SDATA = ack                            ' in case of "ack", pull down DATA-Line
    high SCK                                ' clk #9 for ack
    low SCK
    high SDATA                              
    TRISC.4 = 1                             ' release SDATA-line
    return
    
    softreset:
    ' resets the sensor by a softreset
    errorr = 0
    GOSUB connectionreset                   ' reset communication
    value = resett
    gosub writebyte                         ' send RESET-command to sensor
    return
    Last edited by ScaleRobotics; - 6th April 2011 at 15:26. Reason: added code tags

  15. #15


    Did you find this post helpful? Yes | No

    Unhappy sht11 vs. 16f84A

    I'm using the above code with a 16f84a and getting a consistent number, which is clearly wrong. I'm getting humvalue 16003 and tempval 4000. And since I haven't burst into flames this seems unlikely to be accurate.

    I also tried using a modified Keunyoung Oh's code for the 16f877 (found http://itp.nyu.edu/physcomp/sensors/Code/SHT11 ) but received similar results (consistent & wildly inaccurate numbers), though with different numbers.

    Any idea why this might be?

    Also, as a possible explanation: I'm using the DIP sht11 which has a 117 on the sensor. I'm assuming I should use the pin diagram which goes with sensirion sht11 sensor module #28018, but all the other pin diagrams are different.

    any suggestions would be helpful.

    thanks,
    Adam

  16. #16


    Did you find this post helpful? Yes | No

    Post sht11 v 16f84a follow up

    here's the full code I'm currently (trying to use) everything compiles and publishes in PBP, but still no good data. is my code messed up?
    Code:
    '*******************************[ SHT11 Sample Code ]********************************
    ' File...... SHT11.bas
    ' Purpose... SHT11 digital humidity sensor sample code
    ' MCU....... Microchip PIC16F877
    ' Software.. Converted to Proton+ 2.0 from PBPro ver 2.4
    ' Author.... Brandon Tarr
    ' E-Mail.... [email protected]
    ' Web....... http://www.spectrumedix.com
    ' Started... May 15, 2002
    ' Updated...
    ' Version... 1.0
    '************************************************* *************************
    
    'device 16f884a
    
    DEFINE xtal 4
    Define LCD_DREG PORTD
    Define LCD_DBIT 4
    Define LCD_RSREG PORTE
    Define LCD_RSBIT 0
    Define LCD_EREG PORTE
    Define LCD_EBIT 1
    
    TEMP con 1
    HUMI con 2
    ' adr command r/w
    Symbol statusregw = $06 ' 000 0011 0
    Symbol statusregr = $07 ' 000 0011 1
    Symbol measuretemp = $03 ' 000 0001 1
    Symbol measurehumi = $05 ' 000 0010 1
    Symbol resett = $1e ' 000 1111 0
    
    ' -----[ Variables ]---------------------------------------------------------------------
    ledPin             var     PORTB.0
    ledVar var byte
    
    rxPin              var     PORTB.3
    txPin              var     PORTB.2
    SCK var PORTA.4 ' SHT11 SCK
    SDATA var PORTB.1 ' SHT11 DATA
    
    i  var byte
    f var byte
    value var byte
    errorr var bit
    mode var byte
    ack var bit
    
    vall var byte
    pktvalue var word
    pktchksum var byte
    
    humival var word
    tempval var word
    dewpoint var byte
    checksum var byte
    
    ' -----[ Initialization ]----------------------------------------------------------------
    'ADCON1 = 7 ' Set PORTA and PORTE to digital
    'Low PORTE.2 ' LCD R/W line low (W)
    Pause 500 ' Wait for LCD to start
    'lcdout $fe, 1
    
    ' -----[ Main Code ]---------------------------------------------------------------------
    usetheSHT11:
        SerOut2 txPin, 16468, [" ", 10, 13]
        High ledPin          ' Turn on LED connected to PORTB.0
        Pause 500       ' Delay for .5 seconds
        Low ledPin           ' Turn off LED connected to PORTB.0
    
        gosub connectionreset
        value = measurehumi
        gosub measure ' measure humidity
        humival = pktvalue * 1000
        humival = DIV32 4095
        'lcdout $fe, 2, " ", $fe, 2, "Humidity: ", dec humival / 10, ".", dec humival // 10, "%"
        value = measuretemp
        gosub measure ' measure temperature
        tempval = pktvalue * 1000
        tempval = DIV32 16383
        'lcdout $fe, $c0, " ", $fe, $c0, "Temperature: ", dec tempval / 10, ".", dec tempval // 10, 223, "C"
        SerOut2 txPin, 16468, ["humival  ", DEC humival, 10, 13]
        SerOut2 txPin, 16468, ["tempval  ", DEC tempval, 10, 13]
    
        pause 500 '100 decrease sample time
    goto usetheSHT11
    
    ' -----[ Subroutines ]-------------------------------------------------------------------
    connectionreset:
    ' communication reset: DATA line is high and at least 9 SCK cycles followed by transstart
    ' ________________________________________ _____
    ' SDATA: |_____|
    ' _ _ _ _ _ _ _ _ _ __ __
    ' SCK: _| |_| |_| |_| |_| |_| |_| |_| |_| |___| |__| |___
        input SDATA
        high SDATA
        low SCK ' set initial state
        for i = 1 to 9 ' 9 SCK cycles
        high SCK
        low SCK
        next
        gosub transstart ' transmission start
    return
    
    transstart:
    ' generates a transmission start
    ' ___ _____
    ' SDATA: |_____|
    ' __ __
    ' SCK: __| |__| |___
    
        high SDATA
        low SCK ' set initial state
        high SCK
        low SDATA
        low SCK
        high SCK
        high SDATA
        low SCK
    return
    
    measure:
    ' makes a measurement (humidity/temperature) with checksum
        errorr = 0
        gosub transstart ' transmission start
        gosub writebyte
        for i = 1 to 255 ' wait until sensor has finished the measurement
            if SDATA = 0 then
                goto meascomplete
        endif
        pause 1
        next
    meascomplete:
        if SDATA != 0 then ' or timeout (~2 sec.) is reached
            errorr = 1
        endif
        ack = 1
        gosub readbyte ' read the first byte (MSB)
        pktvalue.highbyte = vall
        gosub readbyte ' read the second byte (LSB)
        pktvalue.lowbyte = vall
        ack = 0
        gosub readbyte ' read checksum (no acknowledge to put sensor in "sleep" mode)
        pktchksum = vall
    return
    
    writebyte:
        ' writes a byte on the Sensibus and checks the acknowledge
        errorr = 0
        i = $80
        while i > 0
            if (i & value) != 0 then ' masking value with i
                high SDATA ' write to SENSI-BUS
            else
                low SDATA
            endif
            high SCK ' clk for SENSI-BUS
            low SCK
            i = i / 2 ' shift bit for masking
        wend
        high SDATA
        TRISB.1 = 1 ' release SDATA-line
        high SCK ' clk #9 for ack
        errorr = SDATA ' check ack (SDATA will be pulled down by SHTXX)
        low SCK
    return
    
    readbyte:
    ' reads a byte from the Sensibus and gives an acknowledge in case of "ack=1"
        vall = 0
        high SDATA
        TRISB.1 = 1 ' release SDATA-line
        i = $80
        while i > 0
            high SCK ' clk for SENSI-BUS
            if SDATA = 1 then ' read bit
                vall = vall | i
            endif
            low SCK
            i = i / 2
        wend
        TRISB.1 = 0 ' grab SDATA-line
        SDATA = ack ' in case of "ack", pull down DATA-Line
        high SCK ' clk #9 for ack
        low SCK
        high SDATA
        TRISB.1 = 1 ' release SDATA-line
    return
    
    softreset:
    ' resets the sensor by a softreset
        errorr = 0
        GOSUB connectionreset ' reset communication
        value = resett
        gosub writebyte ' send RESET-command to sensor
    return
    Last edited by ScaleRobotics; - 6th April 2011 at 15:23. Reason: added code brackets for code tags

  17. #17
    Join Date
    Jan 2008
    Location
    Dublin, Ireland
    Posts
    33


    Did you find this post helpful? Yes | No

    Default

    Hmmmm. This was a valid interesting topic.... pity it ends in the middle of nowhere without a solution!

  18. #18
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tonyfelloni View Post
    Hmmmm. This was a valid interesting topic.... pity it ends in the middle of nowhere without a solution!
    I think there are a couple of other working examples somewhere here on the forums.
    And heck, if the original poster doesn't care if the problem is solved, why should anyone else?

  19. #19
    Join Date
    Jan 2008
    Location
    Dublin, Ireland
    Posts
    33


    Did you find this post helpful? Yes | No

    Default

    Hey Skimask

    I care because its relevant to something I am working on now.... To find the perfect thread....only to discover you have been led up the garden path, haha. Not to worry, I did see a few other relevant posts elsewhere.

    Cheers
    Tony

Similar Threads

  1. Watchdog Timers
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th August 2014, 18:03
  2. INT2 anomaly in DT_INTS-18??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th February 2010, 20:07
  3. capture/repeat data ?
    By Sam in forum Serial
    Replies: 44
    Last Post: - 27th November 2006, 03:19
  4. A little DTMF help
    By Travin77 in forum mel PIC BASIC Pro
    Replies: 48
    Last Post: - 30th May 2006, 01:31
  5. Serout PIC16F628 to PC R18iXL Board
    By Spindle in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th June 2005, 00:29

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