当前位置:首页 > 嵌入式 > 嵌入式教程
[导读]测试基于linux-2.6.27的9G9260开发板I2C驱动

1,找到drivers/i2c/busses/i2c-at91.c文件

root@yuanxh-desktop:/home/yuanxh/sam9260/linux-2.6.27-9g9260# vi drivers/i2c/busses/Makefile

在第28行看到:

obj-$(CONFIG_I2C_AT91) += i2c-at91.o

2, 找到drivers/i2c/busses/Kconfig文件

root@yuanxh-desktop:/home/yuanxh/sam9260/linux-2.6.27-9g9260# vi drivers/i2c/busses/Kconfig

在第259行看到:

config I2C_AT91

tristate "Atmel AT91 I2C Two-Wire interface (TWI)"

depends on ARCH_AT91 && EXPERIMENTAL && BROKEN

help

This supports the use of the I2C interface on Atmel AT91

processors.

This driver is BROKEN because the controller which it uses

will easily trigger RX overrun and TX underrun errors. Using

low I2C clock rates may partially work around those issues

on some systems. Another serious problem is that there is no

documented way to issue repeated START conditions, as needed

to support combined I2C messages. Use the i2c-gpio driver

unless your system can cope with those limitations.

说明AT91 I2C标准驱动不稳定,需要用GPIO模拟!!!

3,编译配置内核

root@yuanxh-desktop:/home/yuanxh/sam9260/linux-2.6.27-9g9260# make menuconfig

进入配置菜单添加驱动到内核:

Device Drivers --->

<*> I2C support --->

<*> I2C device interface

I2C Hardware Bus support --->

<*> GPIO-based bitbanging I2C

4, 编译内核生成驱动

root@yuanxh-desktop:/home/yuanxh/sam9260/linux-2.6.27-9g9260# make

5, 查看内核启动信息

i2c /dev entries driver

i2c-gpio i2c-gpio: using pins 55 (SDA) and 56 (SCL)

6,查看内核系统信息

# cat /proc/devices

会看到

Character devices:

...

89 i2c

...

# cat /sys/devices/platform/i2c-gpio/i2c-adapter:i2c-0/name

i2c-gpio-1

7,建立设备结点

mknod /dev/i2c-0 c 89 0

8,编译测试代码

root@yuanxh-desktop:/home/yuanxh/sam9260/i2ctest-1.0-9g9260# arm-linux-gcc -o i2ctest i2ctest.c

root@yuanxh-desktop:/home/yuanxh/sam9260/i2ctest-1.0-9g9260# cp i2ctest /nfsboot/rootfs/app

9,运行测试代码

# /app/i2ctest

I2C Test version 1.0-9g9260 (yuanxihua@21cn.com) Buile on Jan 5 2009 00:54:45

buf[0x00] = 0x46

...

附件:

//i2ctest.c

#include

#include

#include

#include

#include

#include linux>

#define CHIP_ADDR 0x50 //24C64

#define PAGE_SIZE 32

#define I2C_DEV "/dev/i2c-0"

static int read_eeprom(int fd,char buff[],int addr,int count)

{

int res;

if (write(fd,&addr,1)!=1)

{

printf("Can't write %s's addr %dn",I2C_DEV,addr);

return -1;

}

res = read(fd,buff,count);

printf("read %d bytes at 0x%02xnr",res,addr);

return res;

}

static int write_eeprom(int fd,char buff[],int addr,int count)

{

int res;

int i;

static char sendbuffer[PAGE_SIZE+1];

memcpy(sendbuffer+1,buff,count);

sendbuffer[0]=addr;

res = write(fd,&addr,count+1);

printf("write %d bytes at 0x%02xnr",res,addr);

return res;

}

int main(void)

{

int fd,i,res;

unsigned char buf[PAGE_SIZE];

printf("I2C Test version 1.0-9g9260 (yuanxihua@21cn.com) Buile on %s %snr",__DATE__,__TIME__);

fd=open(I2C_DEV,O_RDWR);

if(fd<0)

{

printf("Can't Open %s !!!nr",I2C_DEV);

return -1;

}

res = ioctl(fd,I2C_TENBIT,0);

res = ioctl(fd,I2C_SLAVE,CHIP_ADDR);

for(i=0;i

{

// write_eeprom(fd,buf,i,1);

}

for(i=0;i

{

read_eeprom (fd,buf+i,i,1);

printf("buf[0x%02x] = 0x%02xnr",i,buf[i]);

}

close(fd);

return 0;

}

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

LED驱动电源的输入包括高压工频交流(即市电)、低压直流、高压直流、低压高频交流(如电子变压器的输出)等。

关键字: 驱动电源

在工业自动化蓬勃发展的当下,工业电机作为核心动力设备,其驱动电源的性能直接关系到整个系统的稳定性和可靠性。其中,反电动势抑制与过流保护是驱动电源设计中至关重要的两个环节,集成化方案的设计成为提升电机驱动性能的关键。

关键字: 工业电机 驱动电源

LED 驱动电源作为 LED 照明系统的 “心脏”,其稳定性直接决定了整个照明设备的使用寿命。然而,在实际应用中,LED 驱动电源易损坏的问题却十分常见,不仅增加了维护成本,还影响了用户体验。要解决这一问题,需从设计、生...

关键字: 驱动电源 照明系统 散热

根据LED驱动电源的公式,电感内电流波动大小和电感值成反比,输出纹波和输出电容值成反比。所以加大电感值和输出电容值可以减小纹波。

关键字: LED 设计 驱动电源

电动汽车(EV)作为新能源汽车的重要代表,正逐渐成为全球汽车产业的重要发展方向。电动汽车的核心技术之一是电机驱动控制系统,而绝缘栅双极型晶体管(IGBT)作为电机驱动系统中的关键元件,其性能直接影响到电动汽车的动力性能和...

关键字: 电动汽车 新能源 驱动电源

在现代城市建设中,街道及停车场照明作为基础设施的重要组成部分,其质量和效率直接关系到城市的公共安全、居民生活质量和能源利用效率。随着科技的进步,高亮度白光发光二极管(LED)因其独特的优势逐渐取代传统光源,成为大功率区域...

关键字: 发光二极管 驱动电源 LED

LED通用照明设计工程师会遇到许多挑战,如功率密度、功率因数校正(PFC)、空间受限和可靠性等。

关键字: LED 驱动电源 功率因数校正

在LED照明技术日益普及的今天,LED驱动电源的电磁干扰(EMI)问题成为了一个不可忽视的挑战。电磁干扰不仅会影响LED灯具的正常工作,还可能对周围电子设备造成不利影响,甚至引发系统故障。因此,采取有效的硬件措施来解决L...

关键字: LED照明技术 电磁干扰 驱动电源

开关电源具有效率高的特性,而且开关电源的变压器体积比串联稳压型电源的要小得多,电源电路比较整洁,整机重量也有所下降,所以,现在的LED驱动电源

关键字: LED 驱动电源 开关电源

LED驱动电源是把电源供应转换为特定的电压电流以驱动LED发光的电压转换器,通常情况下:LED驱动电源的输入包括高压工频交流(即市电)、低压直流、高压直流、低压高频交流(如电子变压器的输出)等。

关键字: LED 隧道灯 驱动电源
关闭