readRegister
Read data from I2C device register
Description
Examples
Read from an I2C Device Register
Create an Arduino object and attach an I2C device object to it.
a = arduino('COM9','Uno','Libraries','I2C');
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
Write value 10 to the I2C device register at address 20.
writeRegister(dev,20,10);
Read from the I2C device register at address 20.
value = readRegister(dev,20)
value = 10
Specify Precision to Read from an I2C Device Register
Create an Arduino object and attach an I2C device object to it.
a = arduino('COM9','Uno','Libraries','I2C');
Use an address to create the I2C device connection.
dev = device(a,'I2CAddress','0x54');
Write value 224 to the I2C device register at address 20 with the precision of uint16
writeRegister(dev, 20, 224,'uint16');
Read from the I2C device register at address 20 with the precision of uint16.
value = readRegister(dev,20,'uint16')
value = 224
Input Arguments
dev
— I2C device connection
device object
I2C device connection, specified as a device
object.
register
— Address of I2C device register
scalar integer from 0 through 255 | hexadecimal | binary
Address of the I2C device register, specified as a scalar integer, hexadecimal, or binary from 0 through 255.
precision
— Data precision
'uint8'
(default) | 'int8'
| 'uint16'
| 'int16'
| 'uint32'
| 'int32'
| 'uint64'
| 'int64'
Data precision, specified as one of the following character vectors:
'uint8'
'int8'
'uint16'
'int16'
'uint32'
'int32'
'uint64'
'int64'
Output Arguments
out
— Value of data
scalar | vector
Value of data stored at the I2C device register, returned as a scalar
or
vector
based on the precision
.
More About
Code Generation Using MATLAB Function Block
Use
readRegister
in a MATLAB® Function block with the Simulink® Support Package for Arduino® Hardware to generate code that can be deployed on Arduino Hardware.
Version History
Introduced in R2014b
See Also
writeRegister
| arduino
| write
| read
Ouvrir l'exemple
Vous possédez une version modifiée de cet exemple. Souhaitez-vous ouvrir cet exemple avec vos modifications ?
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)