1、概述



2、编程
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
int main()
{
int i, fd;
char write_data[256];
char read_data[256];
//打开at24c02对应的sys文件
fd=open("/sys/bus/i2c/devices/0-0050/eeprom", O_RDWR);
//写入数据
for(i=0; i<256; i++)
{
write_data[i]=i;
}
lseek(fd, 0, SEEK_SET);
write(fd, read_data, 256);
//读出来
lseek(fd, 0, SEEK_SET);
read(fd, read_data,256);
//对比
for(i=0; i<256; i++)
{
if(i%16 == 0) print("/n");
printf("%3d ",read_data[i]);
}
return 0;
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/279767.html