Problems Communicating to VCNL4040


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Mar 2016
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: Problems Communicating to VCNL4040

    Hi Richard.

    Thanks for the reply but I don't quite understand. I tried it with no results. Still zero's.
    The data sheet shows this format:

    SLAVE ADDRESS,COMMAND CODE,SLAVE ADDRESS,[DATA_L,DATA_H]

    The second SLAVE ADDRESS has a 1 in the LSB bit of that byte to indicate a READ operation. The first SLAVE ADDRESS has a 0 in the LSB bit of that byte to indicate a WRITE operation.

    Any thoughts?

    Thanks again!

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


    Did you find this post helpful? Yes | No

    Default Re: Problems Communicating to VCNL4040

    The second SLAVE ADDRESS has a 1 in the LSB bit of that byte to indicate a READ operation. The first SLAVE ADDRESS has a 0 in the LSB bit of that byte to indicate a WRITE operation.
    PBP's I2CWRITE and I2CREAD commands require the R/W bit of the Slave address to be 0. PBP will automatically change the R/W bit by itself when it sends the actual bits to the I2C slave device.

    From the PBP manual.
    "The upper 7 bits of the Control byte contain the control code along with chip select or additional address information, depending on the particular device. The low order bit is an internal flag indicating whether it is a read or write command and should be kept clear."

    Thanks for the reply but I don't quite understand. I tried it with no results. Still zero's.
    The data sheet shows this format:

    SLAVE ADDRESS,COMMAND CODE,SLAVE ADDRESS,[DATA_L,DATA_H]
    pbp i2c read from manual
    I2CREAD DataPin, ClockPin, Control,{Address,}[Var{,Var...}]{,Label}



    The address size sent (byte or word) is determined by the size of the variable that is used. If a byte-sized variable is used for the Address, an 8-bit address is sent. If a word-sized variable is used, a 16-bit address is sent. Be sure to use the proper sized variable for the device you wish to communicate with. Constants should no t be used for the Address as the size can vary dependent on the size of the constant .Also, expressions should not be used as they can cause an improper Address size to be sent





    hence
    Code:
    DEVICE_ID        VAR WORD ; a word var to accept the 16 bit reply
     VCNL4040_addr VAR BYTE
     REG_ADDR        VAR BYTE
     VCNL4040_addr=$C0 ; %0110000 <<1
     REG_ADDR= $0C      ;  a byte var to insure correct size register address data is transmitted for that chip
    
    
    
     I2Cread PORTC.4,PORTC.3,VCNL4040_addr,REG_ADDR,[DEVICE_ID]


    Warning I'm not a teacher

Similar Threads

  1. Communicating 2 x-10 transceiver
    By snoopy in forum Schematics
    Replies: 1
    Last Post: - 7th May 2011, 17:10
  2. Communicating between two PICs over DC bus
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th May 2009, 12:57
  3. communicating pic18f452 with pic16f877a
    By tamersoss in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th July 2007, 19:54
  4. Replies: 13
    Last Post: - 22nd November 2006, 08:00
  5. Communicating from one micro to another??
    By jblackann in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th October 2006, 02:53

Members who have read this thread : 2

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