writeRegister

Write data to I2C device register

Description

example

writeRegister(i2cdevObj,registerAddress,dataIn) writes data to the register on I2C device, specified as a device object.

example

writeRegister(i2cdevObj,registerAddress,dataIn,precision) writes data to the register on I2C device, specified as a device object, based on the data precision.

Examples

collapse all

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')

Input Arguments

collapse all

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 device function.

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.

Data Types: double

Address of the I2C device register, specified as a scalar integer from 0 through 255.

Data Types: double

Precision of data to write to the I2C device register.

See Also

Introduced in R2017b