嘿,在那里,我有一个问题,我目前的设置,我从MpU6050芯片接收的数据总是相同的。我对这一级别的编程相当陌生,所以我想问一下,如果我错过了一些显而易见的东西。所以我特别使用PIC24FJ128GA204 MCU作为好奇心板的一部分。因此,我使用XC16编译器。我选择使用MCC生成I2C代码,我可以用它与MPU6050加速度表进行接口。我可以看到引脚RB8=SCL,RB9=SDA,VCC在DEV板上连接到5V,接地到GND。我可以使用I2C1MyMraveWrror()来写入I2C设备及其寄存器。我给寄存器写加速度计数据。为了查看返回的数据,我将它保存在一个数组FROMI2C1WAdMaskRead()中,然后在它的内容后面看到一个断点。因此,我运行这个和甜,数组中填充了一些值,我再次运行循环,同样的数据在那里…我试着改变很多不同的东西。试图写入不同的寄存器(它们似乎都返回相同的数据集,甚至是“我是什么”),并试图在数据表中找到一些配置寄存器。我的第一个想法是使用断点,查找变量可能不是最好的方法。任何帮助都会得到极大的赞赏。请找到下面的相关文件和主文件的源代码。如果有帮助的话,我可以提供整个项目。
以上来自于百度翻译
以下为原文
Hey there,
I'm having a problem with my current setup where the data I am receiving from the MPU6050 chip is always the same. I'm fairly new to this level of programming so thought I'd ask here if I am missing something obvious first.
So specifically I am using the PIC24FJ128GA204 MCU as part of the curiosity board. Therefore I am using the XC16 compiler. I chose to use the MCC to generate the I2C code I could use to interface with the MPU6050 accelerometer. I can see the pins RB8 = SCL, RB9 = SDA, the vcc is attached to 5V on the dev board and ground to GND.
From what I understand. I can use the I2C1_MasterWrite() to write to an I2C device and its register. I write to the register for the accelerometer data. To see what data is returned, I hold it in an array from I2C1_MasterRead() and a breakpoint after to look at it's content. So I run this and sweet, the array is populated with some values, I run through the loop again, the same data is there...
I've tried changing a lot of different things. Trying to write to different registers(They all seem to return the same set of data, even the "what am I" register.) and trying to write to some config registers I found in the data sheet.
My first thought is using a breakpoint and looking in the variable might not be the best way to do it?
Any help would be appreciated massively. Please find the relevant documents to me below and the source code of the main file. I can provide the whole project if it would help.
/**
Generated Main Source File
Company:
Microchip Technology Inc.
File Name:
main.c
Summary:
This is the main file generated using PIC24 / dsPIC33 / PIC32MM MCUs
Descrip
tion:
This header file provides implementations for driver APIs for all modules selected in the GUI.
Generation Information :
Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - pic24-dspic-pic32mm : 1.55
Device : PIC24FJ128GA204
The generated drivers are tested against the following:
Compiler : XC16 v1.34
MPLAB : MPLAB X v4.15
*/
/*
(c) 2016 Microchip Technology Inc. and its subsidiaries. You may use this
software and any derivatives exclusively with Microchip products.
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
TERMS.
*/
/*
* I2C1: SCL = RB8, SDA = RB9
* I2C2: SCL = RB3, RB2
*/
#define FCY 16000000UL
#include
#include
#include
#include
#include "mcc_generated_files/mcc.h"
int main(void)
{
// initialize the device
SYSTEM_Initialize();
uint8_t data[2];
I2C1_MESSAGE_STATUS status;
uint16_t address = 0x6B;
data[0] = (address >> 8); // high address
data[1] = (uint8_t)(address); // low low address
I2C1_MasterWrite(data, 2, 0b1101000, &status);
while (status != I2C1_MESSAGE_COMPLETE);
address = 0x00;
data[0] = (address >> 8); // high address
data[1] = (uint8_t)(address); // low low address
I2C1_MasterWrite(data, 1, 0b1101000, &status);
while (status != I2C1_MESSAGE_COMPLETE);
while (1)
{
address = 0x3B;
data[0] = (address >> 8); // high address
data[1] = (uint8_t)(address); // low low address
I2C1_MasterWrite(data, 2, 0b1101000, &status);
while (status != I2C1_MESSAGE_COMPLETE);
uint8_t accel[20];
I2C1_MasterRead(accel, 20, 0b1101000, &status);
while (status != I2C1_MESSAGE_COMPLETE);
PORTAbits.RA10 = data;
}
return -1;
}