Problems Communicating to VCNL4040


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2016
    Posts
    10

    Default Problems Communicating to VCNL4040

    Hi.

    Has anyone used a Vishay VCNL4040 proximity sensor? I appear to behaving problems communicating to this
    device via I2C. I have tried all weekend with no success. I am using a PIC18F26K22 @ 8MHz.

    I've set the minimum registers (as per app note) as follows:

    PS_CONF1 0x00000000 0x03 low byte

    PS_CONF2 0x00001000 0x03 high byte

    PS_CONF3 0x00000000 0x04 low byte

    PS_MS 0x00000111 0x04 high byte

    For the INT low I chose 0 and the INT high I chose 65535. I have the interrupt deselected any way but pu it in as the app note included it. All I am trying to do is read the PS_DATA_L byte and the PS_DATA_H byte but no go. Just zeros. I am using Picbasic Pro with the ic2write and i2cread command.

    This is how I am writing to the registers.

    I2CWrite PORTC.4,PORTC.3,%01100000,%00000011,[%00111110,%00001000 ] ' $03 command code
    PAUSE 50 I2CWrite PORTC.4,PORTC.3,%01100000,%00000100,[%00000100,%00000111] '$04 command code
    PAUSE 50
    I2CWrite PORTC.4,PORTC.3,%01100000,%00000110,[%00000000,%00000000] '$06 command code
    PAUSE 50
    I2CWrite PORTC.4,PORTC.3,%01100000,%00000111,[%11111111,%11111111] '$07 command code
    PAUSE 50

    Just using "pause 50" to give some time to the prox sensor.



    For reading the " PS_DATA_L byte and the PS_DATA_H byte " I did the following:

    I2Cwrite PORTC.4,PORTC.3,%01100000,%00001000 '$08 command code
    'PAUSE 50
    I2Cread PORTC.4,PORTC.3,%01100001,[PS_DATA_L,PS_DATA_H]
    PAUSE 50

    Now when I read "PS_DATA_L" and " PS_DATA_H" variables I get zero. I have no idea what I am doing wrong. I have
    talked to many I2C devices before. I have more info if needed. Thanks.

    Please help

  2. #2
    Join Date
    Mar 2016
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: Problems Communicating to VCNL4040

    Well I figured out the I2Creadfor the initialization. The slave address byte should be: %11000000 and not %01100000. So good but no matter what register I read from ($00 to $0C) I get zeros. I think I know the problem but don't have a fix. From research I understand that the VCNL4040 can't have a stop bit from the master
    between a I2CWRITE & I2CREAD. So when I switch from a write to a read (as shown below) I get zeros from $08 register.

    I2Cwrite PORTC.4,PORTC.3,%11000000,%00001000 '$08
    pause 5

    I2Cread PORTC.4,PORTC.3,%11000000,[PS_DATA_L,PS_DATA_H]
    PAUSE 5

    The data sheet shows this format to read register $08 instead of just a I2CREAD. There fore when the I2CWRITE finishes I get a stop bit from master and the data sheet shows to use no stop from master between the Write & READ.

    Any ideas how to get around this with out writing my own I2C statement?

    Thanks

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


    Did you find this post helpful? Yes | No

    Default Re: Problems Communicating to VCNL4040

    DEVICE_ID VAR WORD
    VCNL4040_addr VAR BYTE
    REG_ADDR VAR BYTE
    VCNL4040_addr=$C0
    REG_ADDR= $0C



    I2Cread PORTC.4,PORTC.3,VCNL4040_addr,REG_ADDR,[DEVICE_ID]
    Warning I'm not a teacher

  4. #4
    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!

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


    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

  6. #6
    Join Date
    Mar 2016
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: Problems Communicating to VCNL4040

    Hi Richard.

    Thank you for the help!

    I cant wait to try.

Similar Threads

  1. Communicating 2 x-10 transceiver
    By snoopy in forum Schematics
    Replies: 1
    Last Post: - 7th May 2011, 18: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, 13:57
  3. communicating pic18f452 with pic16f877a
    By tamersoss in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th July 2007, 20:54
  4. Replies: 13
    Last Post: - 22nd November 2006, 09:00
  5. Communicating from one micro to another??
    By jblackann in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th October 2006, 03:53

Members who have read this thread : 1

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