Cypress技术william hill官网
直播中

孙榕

7年用户 216经验值
私信 关注
[问答]

I2C未正确接收值

我不是一个I2C的大风扇,并避免它在任何可能的,但我有一个MPU6050陀螺仪/ AcEL传感器使用它,我猜它的时间来学习如何使用I2C在PSoC Creator。看着它的范围,它似乎唤醒传感器,传感器似乎正在返回的值,如果传感器动摇或移动。但是这些价值似乎并没有被UnCube所接受。我一直在使用一个ARDUINO代码来给我一些方向,但是我唯一讨厌的东西是I2C。我将附上我所拥有的项目文件,但我一直在做它,我觉得它现在下山了。最终目标是,我需要能够从传感器获得值,并为以后的项目修改它们。
Cyr.Test.CyWrk.CaseV01.Zip
1.5兆字节

以上来自于百度翻译


     以下为原文
  I am not a big fan of I2C and avoid it where ever possible but I have a MPU6050 gyro/accel sensor using it and I guess its time to learn how to use I2C in the PSoC Creator.  Looking at it on the scope, it seems to be waking up the sensor and the sensor seems to be returning values that change if the sensor is shaken or moved.  But the values don't seem to be getting received by the uController.  I have been using an Arduino code to sort of give me some direction, but the only thing I hate more then I2C is Arduino.  I will attach the project file of what I have, but I have been working on it so long I feel like its going down hill at this point.  End goal is I need to be able to get the values from the sensor and modify them for a later project.


回帖(3)

王琳

2019-1-4 14:43:05
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
举报

孙榕

2019-1-4 15:01:37
引用: ncmza 发表于 2019-1-4 15:57
I2C*MaultRead字节(I2CYACKYDATA)和lt;lt;8将总是导致0(零)。你需要一个类型的演员
(In16)I2C*MaultRead字节(I2CYACKYDATA)& lt;lt;8
字节I2C接口非常简单:在建立组件后,开始使用它

我已经提出了一些你的建议。原来的工作空间似乎已经损坏,所以我重新写出来,并附上了一个新版本的副本。我不想把数据保存为16位值,而是尝试将每个字节保存到它自己的变量中,然后我会担心16位值。再一次,它仍然正确地运行在范围内,但是UC不保存返回给它的值。在SPI通信中,我也遇到过类似的问题,归结为检查UC在开始另一个命令之前已经读完了一个字节。会添加类似于这里需要的东西,这样的线吗?
((I2C.MistMistStudio));= I2CYMSTATIO-RDY-CMPLT)
GROWRK.SARVEVE01.ZIP
1.4兆字节

以上来自于百度翻译


     以下为原文
  I have implemented some of your suggestions.  The original work space seems to have corrupted so I re-wrote it out and attached a copy of the new version.  Instead of trying to have the data saved as 16 bit values, I am trying to just get each byte saved to its own variable and I will worry about 16 bit values afterward.  Again it is still running correctly looking on the scope, but the uC is not saving the values returned to it.  I had a similar problem once with SPI communication, and it came down to having a check for making sure the uC had finished reading a byte before beginning another command.  Would adding something similar to that be required here, a line something like this?
 
while((I2C_MasterStatus() & I2C_MSTAT_RD_CMPLT) != I2C_MSTAT_RD_CMPLT)


举报

孙榕

2019-1-4 15:21:14
引用: hfjydz2013 发表于 2019-1-4 16:15
我已经提出了一些你的建议。原来的工作空间似乎已经损坏,所以我重新写出来,并附上了一个新版本的副本。我不想把数据保存为16位值,而是尝试将每个字节保存到它自己的变量中,然后我会担心16位值。再一次,它仍然正确地运行在范围内,但是UC不保存返回给它的值。在SPI通信中,我也遇到过类似的问题,归结为检查UC在开始另 ...

在这个周末再看一遍之后,我发现问题的一部分是我使用的双向电平移位器将不能与I2C一起工作。我使用的是TXB0104,并被I2C上拉电阻弄糊涂了。我切换到一个简单的基于MOSFET的双向电平移位器来对抗这个,这是最终的代码;
谢谢你的帮助。
Cyr.Test.CyWrk.CaseV01.Zip
1.4兆字节

以上来自于百度翻译


     以下为原文
  After looking it over again this weekend, I found that part of the problem is the bidirectional level shifter I was using will not work with I2C.  I was using a TXB0104 and gets confused by the I2C pull up resistors.  I switched to a simple MOSFET based bidirectional level shifter to combat this and this was the final code;
 
 
 
Thanks for the help.


举报

更多回帖

发帖
×
20
完善资料,
赚取积分