当前位置: 技术问答>linux和unix
IIC 访问DS1307 read:connect time out 错误各位高手看看!。。。。。。。。
来源: 互联网 发布时间:2016-09-01
本文导语: 想通过IIC总线访问DS1307时钟芯片,内核里面有个DS1307的驱动,程序如下: #include "../include/OLP.h" /* I2C_SLAVE is one of macros of ioctl() */ #define I2C_SLAVE 0x0703 #define I2C_TENBIT 0x0704 /* Get ID_PHY from datasheet of ds1037 *...
想通过IIC总线访问DS1307时钟芯片,内核里面有个DS1307的驱动,程序如下:
#include "../include/OLP.h"
/* I2C_SLAVE is one of macros of ioctl() */
#define I2C_SLAVE 0x0703
#define I2C_TENBIT 0x0704
/* Get ID_PHY from datasheet of ds1037 */
#define ID_PHY 0xd9 //通过电压表量的
#define RTC_REG_SECOND 0x00
#define RTC_REG_MINUTE 0x01
#define RTC_REG_HOUR 0x02
#define RTC_REG_DAY 0x03
#define RTC_REG_DATE 0x04
#define RTC_REG_MONTH 0x05
#define RTC_REG_YEAR 0x06
#define RTC_REG_CONTROL 0x07
#define WRITEDS1307 0xd8
#define READDS1307 0xd9
unsigned char read_rtc_code[7];
unsigned char rtc_address[7]={0x00,0x01,0x02,0x03,0x04,0x05,0x06};
void Read_RTC( int file );
unsigned char Read1307( unsigned char add,int file );
int main ( int argc,char **argv )
{
int file;
int ret = -EIO;
//int file;
int adapter_nr = 0;/*i2c device num*/
char filename[20];
unsigned char buf[2];
struct rtc_time tm;
printf("时间芯片测试!n");
sprintf(filename, "/dev/i2c-%d", adapter_nr);
if ((file = open(filename, O_RDWR)) > 1; /* The I2C address */
printf("the addr is %xn",addr);
if( ioctl(file,I2C_TENBIT,0)
#include "../include/OLP.h"
/* I2C_SLAVE is one of macros of ioctl() */
#define I2C_SLAVE 0x0703
#define I2C_TENBIT 0x0704
/* Get ID_PHY from datasheet of ds1037 */
#define ID_PHY 0xd9 //通过电压表量的
#define RTC_REG_SECOND 0x00
#define RTC_REG_MINUTE 0x01
#define RTC_REG_HOUR 0x02
#define RTC_REG_DAY 0x03
#define RTC_REG_DATE 0x04
#define RTC_REG_MONTH 0x05
#define RTC_REG_YEAR 0x06
#define RTC_REG_CONTROL 0x07
#define WRITEDS1307 0xd8
#define READDS1307 0xd9
unsigned char read_rtc_code[7];
unsigned char rtc_address[7]={0x00,0x01,0x02,0x03,0x04,0x05,0x06};
void Read_RTC( int file );
unsigned char Read1307( unsigned char add,int file );
int main ( int argc,char **argv )
{
int file;
int ret = -EIO;
//int file;
int adapter_nr = 0;/*i2c device num*/
char filename[20];
unsigned char buf[2];
struct rtc_time tm;
printf("时间芯片测试!n");
sprintf(filename, "/dev/i2c-%d", adapter_nr);
if ((file = open(filename, O_RDWR)) > 1; /* The I2C address */
printf("the addr is %xn",addr);
if( ioctl(file,I2C_TENBIT,0)