Addressing 16-bit I2C register with Raspberry Pi
조회 수: 17(최근 30일)
표시 이전 댓글
Hi,
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?
댓글 수: 0
답변(1개)
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,
https://www.mathworks.com/help/supportpkg/raspberrypiio/i2c-interface.html
Thanks,
MATLAB Hardware Team
MathWorks
댓글 수: 2
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.
http://ww1.microchip.com/downloads/en/devicedoc/21754m.pdf
If you are still facing any challenges then please contact our Technical Support for further assistance.
https://www.mathworks.com/support/contact_us.html
Thanks,
MATLAB Hardware Team
MathWorks
참고 항목
범주
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!