详解I2CTransfer

The function I2CTransfer:

This function performs one or more I2C read or write operations. pI2CTransferBlock contains a pointer to

the first of an array of I2C packets to be processed by the I2C. All the required information for the I2C

operations should be contained in the array elements of pI2CPackets.


BOOL I2CTransfer(

HANDLE hDev,

PI2C_TRANSFER_BLOCK pI2CTransferBlock);


Parameters:


hDev I2C device handle retrieved from CreateFile()

pI2CTransferBlock

pI2CPackets [in] Pointer to an array of packets to be transferred sequentially

iNumPackets [in] Number of packets pointed to by pI2CPackets (the number of packets to be

transferred)

Return Values Returns TRUE or FALSE, if the result is TRUE, the operation is successful.

I have defined it as so: 

[DllImport("i2csdk.DLL")]

public static extern bool I2CTransfer(IntPtr manejador, I2C_TRANSFER_BLOCK miBloque);


And the trnsfer function definitions are as follow:

I2C_PACKET

This structure contains the information needed to write or read data using an I2C port.

typedef struct {

BYTE byAddr;

BYTE byRW;

PBYTE pbyBuf;

WORD wLen;

LPINT lpiResult;

} I2C_PACKET, *PI2C_PACKET;


Members

byAddr 7-bit slave address that specifies the target I2C device to or from which data is read

or written

byRW Determines whether the packet is a read or a write packet. Set to I2C_RW_READ

for reading and I2C_RW_WRITE for writing. Set to I2C_POLLING_MODE to

force polling mode for transfer.

pbyBuf Pointer to a buffer of bytes. For a read operation, this is the buffer into which data

is read. For a write operation, this buffer contains the data to write to the target

device.

wLen If the operation is a read, wLen specifies the number of bytes to read into pbyBuf.

If the operation is a write, wLen specifies the number of bytes to write from

pbyBuf.

lpiResult Pointer to an int that contains the return code from the transfer operation

I2C_TRANSFER_BLOCK


This structure contains an array of packets to be transferred using an I2C port.


typedef struct {

I2C_PACKET *pI2CPackets;

INT32 iNumPackets;

} I2C_TRANSFER_BLOCK, *PI2C_TRANSFER_BLOCK;


Members

pI2CPackets Pointer to an array of I2C_PACKET objects

iNumPackets Number of I2C_PACKET objects pointed to by pI2CPackets

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值