完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我不是一个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个回答
|
|
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 |
|
|
|
ncmza 发表于 2019-1-4 15:57 我已经提出了一些你的建议。原来的工作空间似乎已经损坏,所以我重新写出来,并附上了一个新版本的副本。我不想把数据保存为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) |
|
|
|
hfjydz2013 发表于 2019-1-4 16:15 在这个周末再看一遍之后,我发现问题的一部分是我使用的双向电平移位器将不能与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. |
|
|
|
只有小组成员才能发言,加入小组>>
752个成员聚集在这个小组
加入小组2075 浏览 1 评论
1829 浏览 1 评论
3645 浏览 1 评论
请问可以直接使用来自FX2LP固件的端点向主机FIFO写入数据吗?
1766 浏览 6 评论
1517 浏览 1 评论
CY8C4025LQI在程序中调用函数,通过示波器观察SCL引脚波形,无法将pin0.4(SCL)下拉是什么原因导致?
516浏览 2评论
CYUSB3065焊接到USB3.0 TYPE-B口的焊接触点就无法使用是什么原因导致的?
370浏览 2评论
CX3连接Camera修改分辨率之后,播放器无法播出camera的画面怎么解决?
413浏览 2评论
360浏览 2评论
使用stm32+cyw43438 wifi驱动whd,WHD驱动固件加载失败的原因?
868浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-29 05:37 , Processed in 0.784011 second(s), Total 52, Slave 46 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号