I2C*MaultRead字节(I2CYACKYDATA)和lt;lt;8将总是导致0(零)。你需要一个类型的演员
(In16)I2C*MaultRead字节(I2CYACKYDATA)& lt;lt;8
字节I2C接口非常简单:在建立组件后,开始使用它
I2CyMasksEngESTEnter(DeVice地址,I2CX Read EXXFIX模式);/初始化事务处理
I2CJMistWrreEngEnter(寄存器);/ /指示要写入哪个寄存器
I2C.MistWrrestEngEnter字节(值);//写入寄存器
I/CyMasksEdStestStor(;)/ /事务结束
当您想从使用的设备读取时(读取两个字节的示例)
I2CyMasksEngESTEnter(DeVice地址,I2CX Read EXXFIX模式);/初始化事务处理
I2C.MistMraveScript(寄存器);/ /指示要写入哪个寄存器
I2C.MaskestEntRead(DeVice地址,I2CX Read x Felx模式);
I2C*MaultRead字节(I2CYACKYDATA);/从寄存器读取
I2C*MaultRead字节(I2CnNaKi数据);/ /从寄存器读取,最后字节是裸的
I/CyMasksEdStestStor(;)/ /事务结束
不太难。请记住,大多数API(除了读取字节之外)都返回一个状态字节,当非零指示错误条件时。
鲍勃
以上来自于百度翻译
以下为原文
I2C_MasterReadByte(I2C_ACK_DATA) << 8 will always result in 0 (zero). You need a type cast as
(int16)I2C_MasterReadByte(I2C_ACK_DATA) << 8
Byte I2C interface is quite simple: After setting up the component and starting it you use
I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE); // Initialize a transaction for writing
I2C_MasterWriteByte(Register); // Indicate which register you want to write to
I2C_MasterWriteByte(Value); // Write to register
I2C_MasterSendStop(); // End of transaction
When you want to read from a device you use (example for reading two bytes
I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE); // Initialize a transaction for writing
I2C_MasterWrite(Register); // Indicate which register you want to write to
I2C_MasterSendRestart(DeviceAddress,I2C_READ_XFER_MODE);
I2C_MasterReadByte(I2C_ACK_DATA); // Read from register
I2C_MasterReadByte(I2C_NAK_DATA); // Read from register, last byte is NAKed
I2C_MasterSendStop(); // End of transaction
Not too difficult. Keep in mind that most of the APIs (except those for reading a byte) return a status byte which, when non-zero indicate an error condition.
Bob
I2C*MaultRead字节(I2CYACKYDATA)和lt;lt;8将总是导致0(零)。你需要一个类型的演员
(In16)I2C*MaultRead字节(I2CYACKYDATA)& lt;lt;8
字节I2C接口非常简单:在建立组件后,开始使用它
I2CyMasksEngESTEnter(DeVice地址,I2CX Read EXXFIX模式);/初始化事务处理
I2CJMistWrreEngEnter(寄存器);/ /指示要写入哪个寄存器
I2C.MistWrrestEngEnter字节(值);//写入寄存器
I/CyMasksEdStestStor(;)/ /事务结束
当您想从使用的设备读取时(读取两个字节的示例)
I2CyMasksEngESTEnter(DeVice地址,I2CX Read EXXFIX模式);/初始化事务处理
I2C.MistMraveScript(寄存器);/ /指示要写入哪个寄存器
I2C.MaskestEntRead(DeVice地址,I2CX Read x Felx模式);
I2C*MaultRead字节(I2CYACKYDATA);/从寄存器读取
I2C*MaultRead字节(I2CnNaKi数据);/ /从寄存器读取,最后字节是裸的
I/CyMasksEdStestStor(;)/ /事务结束
不太难。请记住,大多数API(除了读取字节之外)都返回一个状态字节,当非零指示错误条件时。
鲍勃
以上来自于百度翻译
以下为原文
I2C_MasterReadByte(I2C_ACK_DATA) << 8 will always result in 0 (zero). You need a type cast as
(int16)I2C_MasterReadByte(I2C_ACK_DATA) << 8
Byte I2C interface is quite simple: After setting up the component and starting it you use
I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE); // Initialize a transaction for writing
I2C_MasterWriteByte(Register); // Indicate which register you want to write to
I2C_MasterWriteByte(Value); // Write to register
I2C_MasterSendStop(); // End of transaction
When you want to read from a device you use (example for reading two bytes
I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE); // Initialize a transaction for writing
I2C_MasterWrite(Register); // Indicate which register you want to write to
I2C_MasterSendRestart(DeviceAddress,I2C_READ_XFER_MODE);
I2C_MasterReadByte(I2C_ACK_DATA); // Read from register
I2C_MasterReadByte(I2C_NAK_DATA); // Read from register, last byte is NAKed
I2C_MasterSendStop(); // End of transaction
Not too difficult. Keep in mind that most of the APIs (except those for reading a byte) return a status byte which, when non-zero indicate an error condition.
Bob
举报