Cypress技术william hill官网
直播中

李培珠

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

如何使用I2C从MUPU-6050中读取原始值

你好!
我真的很新鲜,当谈到PSoC编程,我只有一些经验与ARDUNO从一些项目在过去。
我现在的项目是从MUPU-6050中读取原始值,这需要使用I2C。我以前从未使用过,并且我正在努力处理所有的新命令,以及如何/何时使用它们。
我目前所要做的就是读取原始数据并将它们保存在不同的数组中。
我已经附上了我做了这么远的一个示意图,但是此刻我在黑暗中有点绊倒。
Coputs6JPG
21 K

以上来自于百度翻译


     以下为原文
   Hi!
    I am really fresh when it comes to PSoC programming, I only have a little experience with arduino from some projects in the past.
    My project now is to read out the RAW-values from the MPU-6050, which requires the use of I2C. I have never used this before, and I am struggeling with all the new commands, and how/when to use them.
    All I want to do so far is to read the RAW-data and save them in different arrays.
     
    I have attached a schematic of what I've made this far, but I am kind of stumbling in the dark at the moment.


回帖(11)

李培珠

2019-2-21 14:04:13
代码(远未完成):
包括:
空主程序()
{
*将初始化/启动代码放在这里*
UTIN WRDATA;
UTIN RDDATA;
UIT8状态;
UIT8读取标志;
UIT8断裂;
UTIN 8;
UIT8温度;
LCD-CHARESTATE();
LCD-CHARILCISDISPLAY();
I2CY11START();
I2Cy11EnabLeIn();//允许中断,这是大多数I2C操作所必需的。
WrDATA=117;//RG数
UTIN SLaveAdvices=0x68;
定义WRB缓冲区大小(2U)
UIT8 8 SAMPLE段[ WRB BuffelyStand ];
/*CyGloalActuable;*//*不注释此行以启用全局中断。*/
(;)
{
状态=I2CY1IGrimeStEnScript(SLaveAdvor,I2Cy11WrreWest-XFelyMod);
虽然(统计)!= I2CY11MSTRYNNOX错误;
If(状态=I2Cy11MSTRyNoEnror)/检查是否完成传输没有错误
{
I2CY11MistRealWestBuf(SLaveLoad,
(UTI8*)SAMPLE段,
WRB缓冲区大小,
I2Cy11MoDEi完全完成XFER);
LCD-CHARAL PrimtScript(“无错误”);
CyDelay(100);
}
}
}
/*[]文件结束*/

以上来自于百度翻译


     以下为原文
   Code (far from done):
     
    #include
     
    void main()
    {
        /* Place your initialization/startup code here */
     uint8 wrData;
     uint8 rdData;
     uint8 status;
     uint8 readFlag;
     uint8 breakp;
     uint8 masterStatus;
     uint8 temp;
      
     LCD_Char_Start();
     LCD_Char_ClearDisplay();
      
     I2C_1_Start();
     I2C_1_EnableInt(); //Enables interrupt, which is required for most I2C operations.
      
     wrData = 117; //Reg number
     uint8 slaveAddress = 0x68;
     #define WR_BUFFER_SIZE       (2u)
     uint8 sample_segment[WR_BUFFER_SIZE];
     
      
        /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
        for(;;)
        {
            status = I2C_1_MasterSendStart(slaveAddress, I2C_1_WRITE_XFER_MODE);
      
     while (stats != I2C_1_MSTR_NO_ERROR);
     if(status == I2C_1_MSTR_NO_ERROR) // Check if transfer is completed without errors
     {
     I2C_1_MasterWriteBuf(slaveAddress,
     (uint8 *)sample_segment,
     WR_BUFFER_SIZE,
     I2C_1_MODE_COMPLETE_XFER);
     LCD_Char_PrintString("NO ERROR");
     CyDelay(100);
     }  
        }
    }
     
    /* [] END OF FILE */
            
举报

王琳

2019-2-21 14:11:51
欢迎来到PSOCS的迷人世界!
乍一看:
I2C是中断驱动的,因此必须启用全局中断。
在这里上传完整的项目总是明智的,所以我们都可以看看。要做到这一点,在创建者“文件& GT;创建工作区束(最小)”,然后上传由此产生的档案。
对于新手来说,C语言和编程通常也是个问题。当项目增长时,它变得越来越复杂,所以当你早点开始把它分成更小的部分时,它会对你有所帮助。因此,您的主体()可能看起来像
主体()
{
初始化硬件();
(永远)
{
Read MMP6050();
写入文件();
}
}
记住:一个(纽约)项目变得复杂。而且,一个函数“RealMp6060-()”可以很容易地在你的下一个项目中重新使用。
快乐编码
鲍勃

以上来自于百度翻译


     以下为原文
  Welcome in the fascinating world of PSoCs!
    At very first sight:
    The I2C is interrupt-driven, so you MUST enable global interrupts.
     
    It is always advisable to upload the complete project here, so that we all can have a look at. To do so, in Creator "File -> Create Workspace Bundle (minimal)" and then upload the resulting archive here.
     
    For newbees usually C-language and programming turns out to be a problem, too. When the project grows it becomes more and more complex, so when you start early to divide it into smaller pieces it will help you. so your main() may look something like
    main()
    {
       InitializeHardware();
       while(forever)
        {
            ReadMPU6050();
            WriteToLCD();
        }
    }
    Remember: a(ny) project gets complicated. And: A function "ReadMPU6050()" can easily be re-used in your next project.
     
    Happy coding
    Bob
举报

杨军

2019-2-21 14:30:42
假设你连接SCL SDA在加速,没有辅助连接
哪个没有拉柱?
也有一个创造者使用I2C可以修改或项目
看看。
我看到的不同的版本,在注释部分原理图切换SDA,SCL,检查你的
版本。最后我看到你写的I2C,但不是阅读加速?那是配置吗?
写缓冲区中的AcEL命令?
问候,Dana。

以上来自于百度翻译


     以下为原文
  Assumption made you connected SCL to SDA on accel, not the AUX connections
    which do not  have pullups ?
     
    Also in Creator there is a working example project using I2C you can modify or
    look at.
     
    I see on schematic different verison in notes section switched SDA, SCL, check your
    version. Lastly I see you writing to I2C, but not reading the accel ? Was that config
    commands for the accel in the write buffer ?
     
    Regards, Dana.
举报

王建华

2019-2-21 14:43:26
你好
也许有点晚了,但是我很重视的一个例子,我没有测试采用Cypress PSoC 4先锋套件MPU-6050。
汉恩·S·南切兹
I2C.Test.Cyrj.CaseVo.01.Zip
318 K

以上来自于百度翻译


     以下为原文
   Hello
    Maybe a little late, but I'm attaching an example that I did to test MPU-6050 using Cypress PSoC 4 Pionner Kit.
     
    Hernán Sánchez


举报

更多回帖

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