Failed to read i2c device's register with MATLAB Support Package for Raspberry Pi Hardware

6 ビュー (過去 30 日間)
FlyWing
FlyWing 2020 年 12 月 7 日
コメント済み: FlyWing 2020 年 12 月 10 日
Hi everyone. I would like to read a i2c device's register which is connected to a raspberry pi 4b, and I use the support package for raspberry pi hardware. I follow the help document to creat a i2cdev object, then use readRegister command to read, but no matter what register I choose, the returned data is alway zero. Here are the codes:
>> mypi=raspi;
>> imu = i2cdev(mypi,'i2c-1',0x55);
>> readRegister(imu,0x3d,2)
ans =
1×2 uint8 row vector
0 0
However, I can successfully read the nonzero data of the same register in Linux console with i2cget command:
Did I miss something?
  1 件のコメント
FlyWing
FlyWing 2020 年 12 月 8 日
Just to add that I used matlab 2020b, and the raspberrypi 4b was loaded with the mathwork raspbian image of version R20.2.0. I aslo tried matlab 2019b to connect raspberry pi 3b+ with the mathwork raspbian image of version R19.2.0, but the above problem didn't show up.

サインインしてコメントする。

回答 (1 件)

MathWorks MATLAB Hardware Team
MathWorks MATLAB Hardware Team 2020 年 12 月 9 日
編集済み: MathWorks MATLAB Hardware Team 2020 年 12 月 9 日
Hi FlyWing,
Can you please perform following steps and see in all three cases you are getting same values, if not then please contact us using this link https://www.mathworks.com/support/contact_us.html
Note: I have used I2C Peripheral address as 0x5c and Read Register address as 0x2a. You can use 0x55 Peripheral address and 0x3d Read Register address when you try following steps.
Please have a fresh instance of R2020b MATLAB and reboot your Raspberry Pi before proceeding ahead.
(1) Create a raspi object in MATLAB and call readRegister on i2cdev object (like how you did before).
(2) Go to putty terminal and execute "$ i2cget -y 1 0x5c 0x2a w" . Use required addresses here.
(3) Use attached myfile.c to compile and execute to see the register values, here are the steps
* In Putty terminal create a new file using "$ sudo nano myfile.c"
* This opens up a Nano editor, copy the contents of attached file and paste in the editor
* Please change the code in myfile.c to required peripheral address and register address.
* Press 'Ctrl+c' and click yes to save the file
* Now compile and build the myfile.c using "$ gcc -o myfile myfile.c"
* Run the generated binay using "$ chmod +x myfile" and "$ ./myfile"
* You should see the peripheral address, register address and data in the terminal.
Regards,
MathWorks MATLAB Hardware Team
  3 件のコメント
MathWorks MATLAB Hardware Team
MathWorks MATLAB Hardware Team 2020 年 12 月 10 日
Hi FlyWing,
Can you please report this? Also include necessary details of the I2C peripheral which you are using.
Regards,
MathWorks MATLAB Hardware Team
FlyWing
FlyWing 2020 年 12 月 10 日
OK, thanks again.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Raspberry Pi Hardware についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by