本文介绍了在Linux上读写SPI eeprom的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在debian(Beaglebone Black)下使用spi eeprom(at25).我已经编辑了设备树,所以现在我可以读写eeprom了.

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.

Linux中已经有一个spi-at25驱动程序.

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

从eeprom读取

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

写给eeprom

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

但是我想读写eeprom的特定地址.在C程序中有什么方法可以做到这一点?

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

推荐答案

由于此处的eeprom已映射到文件表示形式,因此您可以将其用作普通文件.

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

因此只需open文件,转到要使用seek进行读取/修改/写入的位置,然后执行write.不要忘记closeflush作为文件ID.

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.

这篇关于在Linux上读写SPI eeprom的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-22 10:42