I am trying to write 16 bit data to i2c device . As there are no registers specified to write to the slave device, I am not able to use the built-in wiringPiI2CWriteReg16 Api.

Can some one guide me how to write 16 bit data to device address. I tried using wiringPiI2CWrite() API consecutively for 2 times to write 16 bit data but no luck!



(1) I never use Wiring Pi. So I don't understand your WiringPi problem.

(2) I only know how to use smBus to communicate with I2C devices, with or without registers.

(3) Referring the Appendix A below, I usually

(a) First import smbus,

(b) Define one function to write one byte to the I2C device,

(c) Define another function to write two bytes to the I2C device.

(4) I very seldom use the first function - writing only one byte to the I2C device.

(5) I heavily use the second function - writing two bytes to the I2C device.

(6) I use the i2cBus.write_byte method to write the two bytes.

(7) i2cBus.write does not care what the two write bytes are. It just writes out blindly.

(8) But if the first byte is the device's register address, say config register at address 0x00, and second byte is a data byte 0x55, then 0x55 would be written into the config register.

(9) Now coming back to your problem. What you want is just writing two bytes out, say first byte is 0x77, second byte is 0x88, then i2cBus just again do its job blindly, sending out 0x77, 0x88, I guess this is what you want. Let me know otherwise,

(10) I have a scope to display waveforms, I usually repeated indefinitely write two bytes, and pause 10mS every writing two bytes. I am happy to display the waveforms fro you.


Appendix A - Import and definitions to write one byte and two bytes to I2C device

import smbus
i2cBus1 = smbus.SMBus(1) 

def quickWriteDevOneByte(i2cBus, devAddr, writeByte):
    i2cBus.write_byte(devAddr, writeByte)

def writeDevTwoBytes(i2cBus, devAddr, writeByte1, writeByte2):
    i2cBus.write_byte_data(devAddr, writeByte1, writeByte2)

Appendix B - I2C Sending two bytes

What is the max i2c speed of the raspberry pi 4?

Listing of program to write two bytes to device (actually at the same time read the ADXL345's ID register)

write two bytes


(1) System Management Bus - Wikipedia

(2) SMBus Quick Start Guide, App Note AN4471 - NXP 2010

(3) SMBus Protocol Summary - Linux Kernel documentation v5.4.0

(4) What is the max i2c speed of the raspberry pi 4?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.