Shop OBEX P1 Docs P2 Docs Learn Events
problem with ds1621 sx/b code — Parallax Forums

problem with ds1621 sx/b code

verobelverobel Posts: 81
edited 2007-10-16 17:36 in General Discussion
Fellow sx/b coders;
I am trying to learn SX/B and have run some examples by others successfully but..
I wired up a 2 digit 7 seg. lcd on the PDBoard and initially got it to count from 0 to 99 in a loop.
Next I added 2 I2C chips DS1621 (no examples available) and 24LC64 (some examples available).
In the current program TempDI2.SXB I am trying to display the temperature but get -5· when I expect ~22
The new code (added to the previously working program) is shown below. The full program listing is attached.

Main:
· DO
····· tempC = GET_TEMP
····· tens = tempC / 10
····· ones = tempC // 10
· ...

' Subroutine Code
'
' GET_TEMP
' gets temp from DS1621 using I2C commands
' USE: temp = GET_TEMP
·GET_TEMP:

· I2CSTART SDA
· I2CSEND SDA, addrW························· ' prepare for convert command
· I2CSEND SDA, cmdConv··· ' request convert 1 temp. sample
· I2CSEND SDA, addrR··· ' prepare for readTemp command
· I2CRECV SDA, tempIn_MSB, Ack·· ' read the 2 bytes
· I2CRECV SDA, tempIn_LSB, Nak
· I2CSTOP SDA
· RETURN tempIn_MSB··· ' ignore 1/2 deg LSB for now
·Could some one confirm if the I2C sequence of commands is good.
·Could some one spot any obvious error in my SX/B code that would explain the wrong output -5 on the display?

·I believe the wiring is good: have Ra.0=SDA 1621.1,·Ra.1=SCL 1621.2 both with 4.7k pullup resistors.
A0=1 (5V), A1=0,A2=0
Thanks, John

Comments

  • BeanBean Posts: 8,129
    edited 2007-10-16 15:32
    I don't have a DS1621, but looking at the data sheet it looks like you need something like:

    · I2CSTART SDA
    · I2CSEND SDA, addrW························· ' prepare for convert command
    · I2CSEND SDA, cmdConv··· ' request convert 1 temp. sample
    · I2CSTOP SDA
    · PAUSE 750 ' Allow time for conversion
    · I2CSTART SDA
    · I2CSend SDA, addrW
    · I2CSend SDA, cmdReadT
    · I2CSTART SDA
    · I2CSEND SDA, addrR··· ' prepare for readTemp command
    · I2CRECV SDA, tempIn_MSB, Ack·· ' read the 2 bytes
    · I2CRECV SDA, tempIn_LSB, Nak
    · I2CSTOP SDA


    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My goal is to live forever...Or die trying.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • verobelverobel Posts: 81
    edited 2007-10-16 17:08
    I tried that and it works nicely.
    I had tried to step thru the assembler in Debug.. but that was of a barrier, even with the comments. So I was a bit relieved when the error was found in the higher level code.
    I think I had some confusion on the data sheet about the need to repeati the Start command.
    Thanks for your help, John
  • BeanBean Posts: 8,129
    edited 2007-10-16 17:36
    Your welcome John. Glad you got it working.

    Since the SX/B compiler is my baby, I'm the only one that can "blame the compiler first" [noparse];)[/noparse]

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My goal is to live forever...Or die trying.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
Sign In or Register to comment.