at24c02的写操作可以直接调用write()函数实现。
可以直接进行byte write 或者 page write
在进行page write的时候需要计算好页的起始地址。
程序的使用如下:
page write
./wat24 0 1 2 3 4 5 6 7 8
表示从at24c02中word address为0的地址开始写入1~8。
./wat24 1 1 2 3 4 5 6 7 8
表示从at24c02中的word address为1的地址开始写入1~8数据,但是1是page0内的地址,地址非页对齐。
所以最后在page0内的数据是8 1 2 3 4 5 6 7,8被写到page0的首地址处了。
byte write
./wat24 255 1
byte write相对简单。255表示at24c02中的一个地址,1是向此地址中写入的数据。
读测试程序
#include
#include
#include
#include
#include
#include
structi2c_rdwr_ioctl_data rdwrdata;
intmain(intargc,char*argv[])
{
inti, err;
intfd;
charwordaddr;
char*rdbuf1;
char*rdbuf2;
intbytenum;
if(argc
printf("please input as:");
printf("./