微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > S3C2440模拟IIC方式操作EEPROM

S3C2440模拟IIC方式操作EEPROM

时间:12-03 来源:互联网 点击:

register_chrdev(0,"EEPROM_Chrdev",&EEPROM_File_Ops);
g_p_class = class_create(THIS_MODULE, "EEPROM");
g_p_device = device_create(g_p_class, NULL,MKDEV(g_major, 0), NULL,
"i2c-%d", 1);

GPECON = ioremap(0x56000040,4);
GPEDAT = ioremap(0x56000044,4);

return ret;
}

static void __exit EEPROM_exit(void)
{
printk("-----EEPROM Exit---------\n");

iounmap(GPECON);
iounmap(GPEDAT);

device_destroy(g_p_class,MKDEV(g_major, 0));
class_destroy(g_p_class);
unregister_chrdev(g_major,"EEPROM_Chrdev");

}

module_init(EEPROM_init);
module_exit(EEPROM_exit);

MODULE_AUTHOR("wit_yuan");
MODULE_DESCRIPTION("I2C-EEPROM by wit_yuan 2016-09-17 at beijing");
MODULE_LICENSE("GPL");

/*************end of file for EEPROM driver*****************************/


2.EEPROM.h文件:

#ifndef _EEPROM_H_
#define _EEPROM_H_


#endif


第二部分是Makefile文件内容:

obj-m:=EEPROM.o

KERNEL_DIR:= /home/wityuan/Downloads/linux-3.12.57

PWD:=$(shell pwd)

all:
make -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules

clean:
rm *.o *.ko *.mod.clean


第三部分是应用层的测试程序EEPROM_App.c文件:

#include
#include
#include
#include
#include
#include

#define EEPROM_MAGIC m
#define EEPROM_WRITE _IOW(EEPROM_MAGIC,0,int)
#define EEPROM_READ _IOR(EEPROM_MAGIC,1,int)

typedef struct IIC_Struct{
unsigned char u_device_address;
unsigned char u_reg_address;

}T_IIC_Struct;

static T_IIC_Struct g_t_iic_struct;

int main(int argc,char *argv[])
{
int i_fd;
int i = 0;
unsigned char u_array_buf[10];

unsigned char u_array_write_buffer[10];

i_fd = open("/dev/i2c-1",O_RDWR);

if(i_fd < 0)
{
printf("open device error\n");
return -1;
}

printf("----open device ok----\n");

g_t_iic_struct.u_device_address = 0x50;
g_t_iic_struct.u_reg_address = 0x0;

//初始化写数据的数组
for(i = 0 ; i < 10 ; i ++)
u_array_write_buffer[i] = i + 1;

ioctl(i_fd,EEPROM_WRITE,&g_t_iic_struct);

//写数据内容
write(i_fd,u_array_write_buffer,10);

//读取EEPROM的数据

read(i_fd,u_array_buf,10);

printf("\nread :\n");
for(i = 0; i < 10 ; i ++)
printf("0x%0x ",u_array_buf[i]);

printf("\n");

while(1);

return 0;
}


代码结束了,具体的iic协议解释性内容,还是一样,参考stm32的模拟iic操作EEPROM吧。

这次,贴出一个实现效果图:

好了,这就是本节的内容了。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top