|
#define IOCTL_I2C_READ 0x40000
#define IOCTL_I2C_WRITE 0x40004
//----------------lm75地址、配置字-----------------//
#define lm75_WR_ADDRESS 0x9e //1001 111 0 写
#define lm75_RD_ADDRESS 0x9f //1001 111 1 读
//#define LM75_REG_TEMP 0x00 //指针寄存器选择 TEMP
#define LM75_REG_TEMP 0x00
#define LM75_REG_CONF 0x01
#define LM75_REG_TEMP_HYST 0x02
#define LM75_REG_TEMP_OS 0x03
evc上的程序是这样的:
opendevice:
handle = CreateFile(L"I2C0:",GENERIC_READ|GENERIC_WRITE,NULL,NULL,OPEN_EXISTING,NULL,NULL);
可以看到正常打开,
读和写如下:
DWORD Ret;
DWORD RetBytes;
BYTE pBuffin[2] = {0};
BYTE pBuffOut[2] = {0};
int i;
I2C_IO_DESC xx;
xx.SlaveAddr=lm75_WR_ADDRESS;
xx.WordAddr=LM75_REG_TEMP;
xx.Count=1;
xx.pData=pBuffOut;
Ret=DeviceIoControl(handle,IOCTL_I2C_WRITE,&xx,sizeof(xx),NULL,0,&RetBytes,NULL); //
memset(pBuffin,0,2);
Sleep(1);
xx.SlaveAddr=lm75_RD_ADDRESS;
xx.WordAddr=LM75_REG_TEMP;
xx.Count=2;
xx.pData=pBuffin;
Ret=DeviceIoControl(handle,IOCTL_I2C_READ,&xx,sizeof(xx),NULL,0,&RetBytes,NULL); //
这些步骤不对吗,请帮分析分析! |
|