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

out = readRegister(dev,register)
out = readRegister(dev,register,precision)

Description

example

out = readRegister(dev,register) returns data read from the I2C device register.

example

out = readRegister(dev,register,precision) also specifies the data precision.

Examples

collapse all

Create an Arduino object and attach an I2C device object to it.

a = arduino();

Use an address to create the I2C device connection.

dev = device(a,'I2CAddress','0x55')
dev = 
  device with properties:

             Interface: 'I2C'
            I2CAddress: 85 ('0x55')
                   Bus: 0
                SCLPin: 'A5'
                SDAPin: 'A4'
               BitRate: 100000 (bits/s)

Show functions

Read from the I2C device register at address 20.

value = readRegister(dev,20)
value = 255

Copyright 2014 The MathWorks, Inc.,

Create an Arduino object and attach an I2C device object to it.

a = arduino();

Use an address to create the I2C device connection.

dev = device(a,'I2CAddress','0x55');

Read from the I2C device register at address 20 with the precision of uint16.

value = readRegister(dev,20,'uint16')
value = 65535

Copyright 2014 The MathWorks, Inc.,

Input Arguments

collapse all

I2C device connection, specified as a device object.

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

Data precision, specified as one of the following character vectors:

  • 'uint8'

  • 'int8'

  • 'uint16'

  • 'int16'

  • 'uint32'

  • 'int32'

  • 'uint64'

  • 'int64'

Output Arguments

collapse all

Value of data stored at the I2C device register, returned as a returned as a scalar or vector based on the precision.

Introduced in R2014b