Multi-digit word variable to string


Closed Thread
Results 1 to 40 of 44

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Richard,

    really thanks for your time.

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

    Code:
    tempir = (temp.highbyte << 8) + temp.lowbyte
    Then in the equation i have added the following
    Code:
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    Your way is much more efficient and works just as expected. Im very happy.

    Now what is wrong with the I2C command?
    Attached Images Attached Images  

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,643


    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

  3. #3
    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?

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


    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

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,643


    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 13:13. Reason: wiki
    Warning I'm not a teacher

  6. #6
    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.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,643


    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 ?

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    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

  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: 1127
Size:  92.8 KB
    Last edited by astanapane; - 19th December 2021 at 13:54.

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Quote Originally Posted by astanapane View Post
    Richard,

    Then in the equation i have added the following
    Code:
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    Well, if that compiler could do floating, maybe it could be used. But in PBP integer math? I do not think so. You need what Richard did as a workaround.

    Ioannis

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