Addressing 16-bit I2C register with Raspberry Pi

조회 수: 10 (최근 30일)
HenrikW
HenrikW 2021년 4월 27일
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?

답변 (1개)

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,
https://www.mathworks.com/help/supportpkg/raspberrypiio/i2c-interface.html
Thanks,
MATLAB Hardware Team
MathWorks
  댓글 수: 2
HenrikW
HenrikW 2021년 5월 16일
Hi,
thanks for the Answer, I tried this before but it dosen't fix the problem! Frankly, this approach produces significantly more problems.
1. >> write(<obj_here>, <address_here>, 'uint16'); results in wrong output address bits. The 16-bit address needs to be split into two 8-bit components (low-bit and high-bit). Than the output on the i2c interface should be: [w + 7-bit dev. address] + [high-bit] + [low-bit]. However, the measured (with logic analyzer) output on the interface is: [w + 7-bit dev. address] + [low-bit] + [high-bit].
2. >> dataRead = read(<obj_here>, <length_of_data_here>); starts again with the device address, in my case it should only provide the clock for the read data.
Using the APIs the output looks as follows:
[w + 7-bit dev. address] + [low-bit (register address)] + [high-bit (register address)] + [r + 7-bit dev. address] + [read data] + [read data] + ...
to successfully read from the eeprom the output has to be:
[r + 7-bit dev. address] + [high-bit (register address)] + [low-bit (register address)] + [read data] + [read data] + ...
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.
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

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

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for Raspberry Pi Hardware에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by