This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

readRegister

Read data from I2C device register

Syntax

outdatai2c = readregister(i2cdevObj,registerAddress)
outdatai2c = readregister(i2cdevObj,registerAddress, precision)

Description

example

outdatai2c = readregister(i2cdevObj,registerAddress) returns data read from the device register of I2C device, specified as a device object.

example

outdatai2c = readregister(i2cdevObj,registerAddress, precision) returns data read from the device register of 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 read data from register at address 20.

datai2cdev1 = readregister(i2cdev1, 20)

Use the I2C device object to read data from register at address 20, with a precision of uint16.

datai2cdev1 = readregister(i2cdev1, 20, '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.

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

Data Types: double

Precision of data to read form the I2C device.

Output Arguments

collapse all

The value of data read from the I2C device register, returned as a vector based on the precision.

Introduced in R2017b