Addressing 16-bit I2C register with Raspberry Pi

13 visualizaciones (últimos 30 días)
HenrikW
HenrikW el 27 de Abr. de 2021
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?

Respuestas (1)

MathWorks MATLAB Hardware Team
MathWorks MATLAB Hardware Team el 13 de Mayo de 2021
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 comentarios
HenrikW
HenrikW el 16 de Mayo de 2021
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 el 17 de Mayo de 2021
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

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Support Package for Raspberry Pi Hardware en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by