Addressing 16-bit I2C register with Raspberry Pi

조회 수: 17(최근 30일)
HenrikW 2021년 4월 27일
I try to read from a 24LC512 eeprom via the I2C interface of a raspberry pi. My Problem is now, that the EEPROM has 16-bit register addresses. I tried to use
[value] = readRegister(myi2cdevice,register,dataPrecision)
but 'register' supports only 8-bit (0 to 255) values. Is there a workaround for this problem?


MathWorks MATLAB Hardware Team
MathWorks MATLAB Hardware Team 2021년 5월 13일
Hi Henrik,
You can use write() and read() APIs for the same. Here is the code snippet that can help you,
>> % Read the data
>> write(<obj_here>, <address_here>, 'uint16');
>> dataRead = read(<obj_here>, <length_of_data_here>, 'uint16')
You can find more info about these APIs in following link,
MATLAB Hardware Team
  댓글 수: 2
MathWorks MATLAB Hardware Team
MathWorks MATLAB Hardware Team 2021년 5월 17일
Hi Henrik,
The reason that you are seeing address low byte first and then address high byte is probably due to the endiannes of your PC/hardware setup. Currently we support only little-endian devices, it is a limitation in our support package and we plan to address this issue in future releases.
You can execute the following command and see if you PC is if little-endian.
>> [~,~,endian] = computer
If your computer is little-endian ('L') then you may need to swap address bytes and then perform write and read operations. Hope this should solve no. (1).
For no. (2), you may still want to start with the device address. As per the following datasheet you need to do write [Start device_Address Write Addr_High Addr_low] + read [Start device_address data] for reading data from the memory.
If you are still facing any challenges then please contact our Technical Support for further assistance.
MATLAB Hardware Team

댓글을 달려면 로그인하십시오.


Find more on MATLAB Support Package for Raspberry Pi Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by