开发板是fl2440板子。。跑的Linux3.0内核
这里的EEPROM只是初步的实现。。并没有具体的分析函数。。以后会具体的分析。。
1.修改内核
改make menuconfig
Device Drivers --->
<*> I2C support --->
--- I2C support
[*] Enable compatibility bits for old user-space
<*> I2C device interface
< > I2C bus multiplexing support
[ ] Autoselect pertinent helper modules
<*> SMBus-specific protocols
I2C Algorithms --->
I2C Hardware Bus support --->
[ ] I2C Core debugging messages
[ ] I2C Algorithm debugging messages
[ ] I2C Bus debugging messages
[*] Misc devices --->
EEPROM support --->
<*> I2C EEPROMs from most vendors
<*> SPI EEPROMs from most vendors
< > Maxim MAX6874/5 power supply supervisor
<*> EEPROM 93CX6 support
2.改arch/arm/mach-s3c2440/mach-smdk2440.c
添加
/*add 24c02 device*/
static struct at24_platform_data at24c02 = {
.byte_len = SZ_2K / 8,
.page_size = 8,
.flags = 0,
};
static struct i2c_board_info __initdata smdk_i2c_devices[] = {
{
I2C_BOARD_INFO("24c02", 0x50),
.platform_data = &at24c02,
},
};
/* add 24c02 end */
并在smdk2440_machine_init中添加
i2c_register_board_info(0, smdk_i2c_devices, ARRAY_SIZE(smdk_i2c_devices));
这样从新编译内核就可以实现eeprom了。。该文件在/sys/devices/platform/s3c2440-i2c/i2c-0/0-0050/eeprom
下面给出一个应用程序。。
#include
#include
#include
#include
#include
#include
#include
int main (int argc, char **argv[])
{
int fd;
int i;
int ret;
char read_data[256];
fd = open("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0050/eeprom", O_RDWR);
if(fd < 0)
{
printf ("open 24c02 fail\n");
return -1;
}
lseek(fd, 0, SEEK_SET); //point the head of eeprom
ret = read(fd, read_data, 256);
if(ret < 0)
{
printf("read error\n");
return -1;
}
else if(ret < 256)
{
perror("incomplete read\n");
printf("%d\n", ret);
return -1;
}
for(i = 0; i < 256; i++)
{
if(i % 16 == 0)
{
printf("\n");
}
printf("%03d ", read_data[i]);
}
printf("\n");
return 0;
}
这样在我们的开发板上就可以运行出来了。。
上一篇:I2C串行总线协议
下一篇:I2C通信之EEPROM
推荐阅读最新更新时间:2024-03-16 16:08