Multi-digit word variable to string


Closed Thread
Results 1 to 40 of 44

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,721


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string


    I found this,if i remember correctly somewhere related to this specific sensor.


    Code:
    tempir = (temp.highbyte << 8) + temp.lowbyte
    maybe but in conjunction with
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07

    its not useful in any way

    Now what is wrong with the I2C command?
    all this achieves is exactly nothing
    Code:
    reg    = $07             ' based on the datasheet $07 is the object's temp
    
    
    grave doubts about all of this  it looks like some mishmash of a C code method where no read/write register command exists as it does in pbp 
    addr   = %10110100       ' $B4  binary value: %10110100
    i2cwrite SDA, scl, addr  ' send write command, shift the address B4, 8 bits where LSB is W = 0
    i2cwrite sda, scl, reg   ' register is $07
    
    
    i2cwrite sda, scl, addr,reg, [some data of some sort]  ' register is $07 ;would be the normal way if you had any data to write 
    
    
    totally bogus in pbp bit 0 should always be 0
    addr   = %10110101       ' $B5  Binary value: %10110101
    
    
    a form of torture to i2c chips with an incomplete transaction
    i2cwrite sda, scl, addr  ' sends read command, shift the address B5, 8 bits where LSB is R = 1, clock idles low
    all that's needed
    reg = $07
    addr = %10110100
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07 ;would be the normal pbp way
    Warning I'm not a teacher

  2. #2
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Richard,

    now i got a bit comfused. If i only add the following, it doent work as expected

    all that's needed
    reg = $07
    addr = %10110100
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07 ;would be the normal pbp way
    But if i add the write mode and I2Cwrite command it works.
    Code:
    reg = $07 ' this is the register for IR temp mode
    addr= %10110100 ; this is the write mode
    
    i2cwrite SDA, SCL, addr 
    i2cread SDA, SCL, addr, reg, [TEMP.lowbyte, TEMP.highbyte]
    the following also works.

    Code:
    reg = $07 ' this is the register for IR temp mode
    addr= %10110100 ; this is the write mode
    i2cwrite SDA, SCL, addr 
    
    addr= %10110101 ; this is the read mode
    i2cread SDA, SCL, addr, reg, [TEMP.lowbyte, TEMP.highbyte]
    if i do not add the following line the code doesnt work.

    Code:
    i2cwrite SDA, SCL, addr
    Shouldnt we write first and then read? ok i understand that we have nothing to write. But why it doent work if i do not add the i2cwrite line?

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,721


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Shouldnt we write first and then read? ok i understand that we have nothing to write. But why it doent work if i do not add the i2cwrite line?
    which is precisely what the i2cread command does for you automatically. it should not ever be necessary to add a extra write , no i2c chip i have ever encountered has needed such treatment


    i2cwrite SDA, SCL, addr
    is an incomplete transaction. if your chip needs it then it is not a true i2c device or something else is occurring.
    a logic analyzer would show what's really happening. its not normal and should be examined further to have any confidence
    that the code is really viable in the long term

    addr = %10110100
    trying to set bit0 [the r/w bit] of a i2c address with pbp's i2c commands is not possible and will not have any effect
    the code will set the r/w bit as needed
    Warning I'm not a teacher

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,721


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    it could be the chip is not really i2c and behaves differently

    try this, at least its a nicer transaction
    i2cwrite SDA, SCL, addr,[7]
    i2cread SDA, SCL, addr,[TEMP.lowbyte, TEMP.highbyte]



    looking at the wiki link you posted, this would do exactly what the smbus timing diagram describes as a proceedure

    PEC var byte
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte,PEC] ' reg = $07 ;would be the normal pbp way

    worth trying
    Last edited by richard; - 19th December 2021 at 14:13. Reason: wiki
    Warning I'm not a teacher

  5. #5
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Hi Richard,

    sure i'll try that, and i will try to figure out what is going on with a logic analyzer.

    I have a saleae logic 8.

    Will try that later today. Many thanks for your time once again.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,721


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    If there is only one MLX90614 sensor, the 7-bits address is 0x00 by default.
    according to wiki addr =0 where did you get B4 from ?

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,175


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    If the chip is the MAX30102, on page 16 seems that reading needs first a write.

    Ioannis

  8. #8
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Quote Originally Posted by Ioannis View Post
    If the chip is the MAX30102, on page 16 seems that reading needs first a write.

    Ioannis
    it is an IR MLX90614

  9. #9
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    wait a sec,

    im reading the manual again from the SENSOR

    https://www.waveshare.com/w/upload/e/e4/MLX90614-EN.pdf

    Name:  ir sensor 2.png
Views: 3622
Size:  92.8 KB
    Last edited by astanapane; - 19th December 2021 at 14:54.

Members who have read this thread : 0

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