BH1750FVI sample code available?


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default Re: BH1750FVI sample code available?

    1 - use the appropriate I2C address for the device based on the hardware pin state
    2) Slave Address
    Slave Address is 2 types, it is determined by ADDR Terminal
    ADDR = ‘H’ ( ADDR ≧ 0.7VCC ) → “1011100“
    ADDR = 'L' ( ADDR ≦ 0.3VCC ) → “0100011“


    2 - the device address for case 1 is $B8 and case 2 is $46 (use one of these values in cnt)
    When you put the address as shown in your code, the leading bit is 0 and the address will be $5c or $23. This is definitely wrong.

    3 - cnt remains the same for I2CWrite and I2CRead. the least significant bit is changed internally by the compiler depending on whether the command is a read or write

  2. #2
    Join Date
    Feb 2013
    Posts
    1,122


    Did you find this post helpful? Yes | No

    Default Re: BH1750FVI sample code available?

    Thanks!
    Tried both, none works, so I guess, I'm missing something else too...

  3. #3
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default Re: BH1750FVI sample code available?

    You ought to be sending this way

    Code:
    Assuming ADDR pin is low
    
        i2cwrite ldta, lclk, $46, adr,  dat
    
    and read by
    
        i2cread ldat, lclk, $46, adr, dat
    make sure the adr and dat match with the register of the device and dat relevant to the register. It should work.

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


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: BH1750FVI sample code available?

    You ought to be sending this way
    not in my view
    addr var byte
    addr= $46
    i2cwrite sda,sck,addr,[opecode]
    i2cread sda,sck,addr,[dat.highbyte,dat.lowbyte]
    Last edited by richard; - 17th May 2022 at 02:56. Reason: got rid of ridiculous alias names
    Warning I'm not a teacher

  5. #5
    Join Date
    Feb 2013
    Posts
    1,122


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: BH1750FVI sample code available?

    Big thanks Richard! now it works!

    here's the code:
    Code:
    adr=$46
    x=0
    cnt=%0100011
    i2cwrite ldta, lclk, adr, cnt
    pause 200
    cnt=%00010001
    i2cwrite ldta, lclk, adr, cnt 
    pause 200
    maik:
    cnt=%00010001
    i2cwrite ldta, lclk, adr, cnt 
    pause 200
    cnt=%0100011
    i2cread ldta, lclk, adr, [x.highbyte, x.lowbyte] 
    pause 200
    lcdout $fe, $1, dec x
    pause 200
    goto maik

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


    Did you find this post helpful? Yes | No

    Default Re: BH1750FVI sample code available?

    Big thanks Richard! now it works!
    as maybe but you are still incorrect , if you use a logic analyzer you will see the transaction ends abnormally



    wrong way
    i2cwrite ldta, lclk, adr, cnt
    correct way
    i2cwrite ldta, lclk, adr, [ cnt ]
    Warning I'm not a teacher

  7. #7
    Join Date
    Feb 2013
    Posts
    1,122


    Did you find this post helpful? Yes | No

    Default Re: BH1750FVI sample code available?

    Well, just added these square brackets - see no difference in readings.

Similar Threads

  1. please who can help me for sample code
    By jasem700 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd February 2009, 20:41
  2. USBJADEM sample code
    By SterlingY in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th March 2007, 00:57
  3. sample code for M25P32
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th January 2007, 02:37
  4. Sample code for pwm
    By Md.Shah in forum mel PIC BASIC
    Replies: 1
    Last Post: - 10th October 2006, 16:59
  5. 12F675 code sample
    By marad73 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 23rd May 2006, 13:53

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