• AVR Freaks

Hot!MCC I2C Code on PIC18F45K40 : Issues with I2C1_Write2ByteRegister()

New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2018/02/01 04:37:38
  • Location: 0
  • Status: offline
2020/12/31 08:21:12 (permalink)

MCC I2C Code on PIC18F45K40 : Issues with I2C1_Write2ByteRegister()

I've got a PIC18F45K40  connected to a proximity sensor VCNL4040. The sensor has 16 bit registers that can be r/w. I'm able to successfully read all of the registers  using the MCC code generated as "I2C1_Read2ByteRegister()". All the readouts match the datasheet.
However when I attempt to use the supplied function I2C1_Write2ByteRegister() to send a 16 bit int it only writes the upper two bytes. For example :
I2C1_Write2ByteRegister(VCNL4040_ADDRESS, VCNL4040_PS_THDL, 0x00121234);

Reads back as 0x1200
I tried to follow the MCC code but it's more convoluted than documented. I did note that in "I2C1_Write2ByteRegister()" if I change 


Reads back as 0x0034
Am I misunderstanding the intention of the library functions?
I2C1_Write1ByteRegister //For an 8 bit register
I2C1_Write2ByteRegister //For a 16 bit register
It's the same on all the VCNL4040 registers, I have an Arduino running an adafruit library successfully so I know these registers can be write/read without issue. We just want to use the PIC18F in production. 

0 Replies Related Threads

    Jump to:
    © 2021 APG vNext Commercial Version 4.5