Read and write to spi eeprom on linux

主宰稳场 提交于 2019-12-11 04:57:07

问题


I want to use my spi eeprom (at25) under debian (Beaglebone Black). I have edited the device tree, so now i can read and write to eeprom.

There is already a spi-at25-driver in Linux.

Reading from eeprom

cat /sys/class/spi_master/spi1/spi1.o/eeprom

writing to eeprom

echo hello > /sys/class/spi_master/spi1/spi1.o/eeprom

But i want to write and read from specific address of the eeprom. Is there any way to do this within a C-Program?

thx


回答1:


As the eeprom here is mapped to a file representation you can use it as a normal file.

So simply open the file, go to the place where you want to read/modify/write with seek and do your write. Don't forget a close or flush for the file id.

It is also possible to mmap your file into your memory of the process and access the memory there as a normal array.



来源:https://stackoverflow.com/questions/26100105/read-and-write-to-spi-eeprom-on-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!