资源简介
I2C-tools-3.0.0 测试工具。可以检测I2C,显示I2C设备地址,以及对I2C进行通讯测试等
代码片段和文件信息
/***************************************************************************
copyright : (C) by 2002-2003 Stefano Barbato
email : stefano@codesink.org
$Id: 24cXX.c 4230 2006-11-10 09:22:12Z khali $
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License or *
* (at your option) any later version. *
* *
***************************************************************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “24cXX.h“
static int i2c_write_1b(struct eeprom *e __u8 buf)
{
int r;
// we must simulate a plain I2C byte write with SMBus functions
r = i2c_smbus_write_byte(e->fd buf);
if(r < 0)
fprintf(stderr “Error i2c_write_1b: %s\n“ strerror(errno));
usleep(10);
return r;
}
static int i2c_write_2b(struct eeprom *e __u8 buf[2])
{
int r;
// we must simulate a plain I2C byte write with SMBus functions
r = i2c_smbus_write_byte_data(e->fd buf[0] buf[1]);
if(r < 0)
fprintf(stderr “Error i2c_write_2b: %s\n“ strerror(errno));
usleep(10);
return r;
}
static int i2c_write_3b(struct eeprom *e __u8 buf[3])
{
int r;
// we must simulate a plain I2C byte write with SMBus functions
// the __u16 data field will be byte swapped by the SMBus protocol
r = i2c_smbus_write_word_data(e->fd buf[0] buf[2] << 8 | buf[1]);
if(r < 0)
fprintf(stderr “Error i2c_write_3b: %s\n“ strerror(errno));
usleep(10);
return r;
}
#define CHECK_I2C_FUNC( var label ) \
do { if(0 == (var & label)) { \
fprintf(stderr “\nError: “ \
#label “ function is required. Program halted.\n\n“); \
exit(1); } \
} while(0);
int eeprom_open(char *dev_fqn int addr int type struct eeprom* e)
{
int fd r;
unsigned long funcs;
e->fd = e->addr = 0;
e->dev = 0;
fd = open(dev_fqn O_RDWR);
if(fd <= 0)
return -1;
// get funcs list
if((r = ioctl(fd I2C_FUNCS &funcs) < 0))
return r;
// check for req funcs
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_READ_BYTE );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_WRITE_BYTE );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_READ_BYTE_DATA );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_WRITE_BYTE_DATA );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_READ_WORD_DATA );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_WRITE_WORD_DATA );
// set working device
if( ( r = ioctl(fd I2C_SLAVE addr)) < 0)
return r;
e->fd =
- 上一篇:滨州电网数据
- 下一篇:DHT22(AM2302)STM32f103程序
相关资源
- I2C读写AT24C02 基于STM32F103 cube116540
- 用DIO 做的I2C程式
- I2C总线接口设计
- 8051F040SMBUS多机通信
- DHT10_I2C驱动.zip
- I2C串行EEPROM应用系统的健壮性设计
- 电子-GravityI2C3.7V锂电池电量计stm32L1
- arduino主机,stm8从机。I2C测试 。每次
- 10位ADC转换器AD5612(stm32_IO口模拟I2C)
- (带有源代码)基于FPGA的模拟I2C接口
- I2C-verilog-(非常详细的i2c学习心得)
- stm32f103iic读取AT24XX全系eeprom
- 分享一个0.96的oled显示驱动,软件模拟
- DAC8571_I2C模式_STM32
- STM32F4 I2C从机中断
- ADS1110stm32驱动自带I2C驱动
- STM32F103C8 例程
- stm32 I2C主从机模式控制代码
- 基于STM32F103硬件I2C读写24Cxx驱动代码的
- Ginkgo_USB-I2C_Classic_Setup_v2.9.2.zip
- I2C从设备接收数据verilog代码实现
- CH341-I2C-labview-应用说明+VI-所有版本都
- Delphi2CPP 和注册机
- STM32_MPU6050DMP硬件I2C读取欧拉角
- 基于FPGA的EEPROM读写系统
- 用stm32硬件I2C和模拟I2C读写EEPROM
- 利用STM32硬件I2C使用加速度传感器AD
- STM32与HTU21的I2C通讯源码
- stm32f103硬件I2C主从通信
- sht20 程序
评论
共有 条评论