Shop OBEX P1 Docs P2 Docs Learn Events
how does I2Cobj work when handeling a ds1624 — Parallax Forums

how does I2Cobj work when handeling a ds1624

darkxceeddarkxceed Posts: 34
edited 2007-01-10 10:29 in Propeller 1
Hello people,

I am new to I2C with the propeller chip.
Now I want to read the temp of the ds1624(which is different than the ds1620).

The commandos have to be:
Start
%10010000
$AC
$00
Stop

Start
%10010000
$EE
Stop

Start
%10010000
$AA
Start
%10010001
RX··············· <receive temp reading 2 bytes long
Stop

There are ofcourse ACK after every byte that is send and·NACK after every byte that is received

How do I handle the I2Cobj.spin because I don't get it really.
I want to keep it as simple as those commando's, and no extra's like checking if there an error.

Best regards,
Bart Veenstra

Comments

  • JavalinJavalin Posts: 892
    edited 2007-01-09 13:49
    Have you read the i2cDemo.spin and i2cObject.spin comments/documentation within the example code? Also I suspect the DS1621 example will help you.

    James
  • darkxceeddarkxceed Posts: 34
    edited 2007-01-09 15:00
    I want to do it with low level code like the funktions :
    PUB i2cStop
    PUB i2cStart
    PUB i2cWrite(i2cData, i2cBits) : ackbit
    PUB i2cRead(ackbit) : i2cData

    But I dont know how to use it.
    Should my code be like below

    i2cObject.i2cStart
    i2cObject.i2cWrite(%10010000, 8)
    i2cObject.i2cWrite($AC, 8)
    i2cObject.i2cWrite($00, 8)
    i2cObject.i2cStop

    if I want to send:

    Start
    %10010000
    $AC
    $00
    Stop

    to adres 4 for example.

    Maybe some one help me a little bit, don't need much help.
  • JavalinJavalin Posts: 892
    edited 2007-01-09 16:02
    Hi,

    You need to read the product datasheet, you seem to be missing some·steps from the communication.

    The manual is here http://datasheets.maxim-ic.com/en/ds/DS1624.pdf

    You really need to look at the DS1621 example as, from a brief look at the ds1624 datasheet, the two products protocols·should be nearly identitical.

    James
  • LitefireLitefire Posts: 108
    edited 2007-01-09 22:39
    do you need to submit any data to the $EE address during the second command (not even a 0/1 to tell it what to do?). do you simply need to access the register?

    ~~Brian
  • LitefireLitefire Posts: 108
    edited 2007-01-09 22:47
    con
      _clkmode = xtal1 + pll16x       
      _xinfreq = 5_000_000
    
      deviceaddress = %10010000
    
      
    obj
      i2c : "i2cobject"
      
    pub start (sda, scl)
      i2c.start
      i2c.init(sda, scl, FALSE)                                        'leave at false if you have pull-up resistors, switch to TRUE to drive pins from prop (not reccomended)
    
    pub command1 : success                                             'sends first command
      success := i2c.writelocation (deviceaddress, $AC, $00, 8, 8)     'sends device's address, then the register, then the data.  8 address bits, 8 data bits
                                                                       'saves acknowledge bit from device to "success"
      return success
    
    pub command 2 : success
      success := i2c.writelocation(deviceaddress, $EE, "command here", 8, 8)
      return success
    
    pub command2_alt   'use if no data is to be sent to $EE
      i2c.i2cstart                                                     'starts i2c 
      i2c.i2cwrite (deviceaddress, 8)                                  'sends device address
      i2c.i2cwrite ($EE, 8)                                            'sends register address
      i2c.i2cstop                                                      'stops i2c
    
    pub read1 : readdata
      readdata := i2c.readlocation (deviceaddress, $AA, 8, 16)         'reads 2 bytes from register $AA (8 address bits, 2 bytes at 8 bits each = 16 data bits)
      return readdata
    
    



    try that. make sure you have pullups on your data and clock lines. it needs i2cobject.spin to be in the same folder (obviously).

    good luck!
  • darkxceeddarkxceed Posts: 34
    edited 2007-01-10 07:01
    Yes I looked at the datasheet and this is what there has to be done:

    Start,%10010000,ACK,$AC,ACK,$00,ACK,Stop <==configuration register. 1shot

    Start,%10010000,ACK,$EE,ACK,Stop <==Start convert.

    Start,%10010000,ACK,$AA,ACK,Start,%10010001,ACK,Receivebyte,ACK,Receivebyte,NACK,Stop <==get 2 byte data

    the last ACK and NACK must send from master to slave.
    The ds1624 is connected to the prop with 2x 4k6 pull-up and 100Ohm resistor in serie to the prop output 28(SCL),29(SDA), the eeprom is also connected there for the propsoftware.


    con
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000

    deviceaddress = %10010000


    obj
    i2c : "i2cobject"

    pub start (sda, scl)
    i2c.start
    i2c.init(sda, scl, FALSE)


    pub Config : success························································· 'sends first command
    success := i2c.writelocation (deviceaddress, $AC, $00, 8, 8)·····'sends device's address, then the register, then the data. 8 address bits, 8 data bits
    return success

    pub Convert····································································· 'use if no data is to be sent to $EE
    i2c.i2cstart······································································ 'starts i2c
    i2c.i2cwrite (deviceaddress, 8)············································· 'sends device address
    i2c.i2cwrite ($EE, 8)··························································· 'sends convert prot.
    i2c.i2cstop········································································'stops i2c

    pub read1 : readdata
    readdata := i2c.readlocation (deviceaddress, $AA, 8, 16)······· ··'reads 2 bytes from register $AA (8 address bits, 2 bytes at 8 bits each = 16 data bits)
    return readdata

    Post Edited (darkxceed) : 1/10/2007 7:05:58 AM GMT
  • darkxceeddarkxceed Posts: 34
    edited 2007-01-10 10:29
    Javalin said...
    Hi,

    You need to read the product datasheet, you seem to be missing some·steps from the communication.

    The manual is here http://datasheets.maxim-ic.com/en/ds/DS1624.pdf

    You really need to look at the DS1621 example as, from a brief look at the ds1624 datasheet, the two products protocols·should be nearly identitical.

    James
    I looked at the exmaple yes, and got it working.
    But I don't know how to get the second byte of·temperatuur.
    This byte contains the precision values lower than 1degree.

    pub·read1·:·readdata
    ··readdata·:=·i2c.readlocation·(deviceaddress,·$AA,·8,·16)·········'reads·2·bytes·from·register·$AA·(8·address·bits,·2·bytes·at·8·bits·each·=·16·data·bits)
    ··return·readdata

    In the upper syntax I set it to 16 to read 2 bytes but the second byte stays %00000000

    If I have the second byte I than can manipulate is because only the last 5 bits contains a·measure value.
    In total the tempreading is 13bits long.

    If I try it in low level code I maybe understand it more.
Sign In or Register to comment.