Write data to I2C device register
Create object for an I2C device that is already connected to I2C bus.
microbitObj = microbit('COM3'); scanI2CBus(microbitObj)
ans = 1×2 string array "0xE" "0x1D"
i2cdev1 = device(microbitObj, 'I2CAddress',"0xE");
i2cdev1 = device with properties: Interface: "I2C" I2CAddress: 14 ("0xE") SCLPin: "P19" SDAPin: "P20" BitRate: 100000 (bits/s)
Use the I2C device object to write data to the I2C device register at address 20.
dataIn = [0 1 2 3 4 5]; writeRegister(i2cdev1, 20, dataIn)
Write data to the I2C device register at address 20, with a precision of uint16.
dataIn = [0 500]; writeRegister(i2cdev1, 20, dataIn, 'uint16')
i2cdevObj— I2C device connection
Device connection to an I2C device, specified as a device object, connected to the
I2C bus on the BBC micro:bit board. The I2C device object is created using the
dataIn— Data to write
Data to write to the I2C device register, specified as a scalar or vector. The range of the values in the array is based on the precision.
registerAddress— Address of I2C device register
Address of the I2C device register, specified as a scalar integer from 0 through 255.
precision— Data precision
Precision of data to write to the I2C device register.