完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
// Copyright (c) 2012-2014 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement // // Texas Instruments (ti) is supplying this software for use solely and // exclusively on TI's microcontroller products. The software is owned by // TI and/or its suppliers, and is protected under applicable copyright // laws. You may not combine this software with "viral" open-source // software in order to form a larger program. // // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL // DAMAGES, FOR ANY REASON WHATSOEVER. // // This is part of revision 2.1.0.12573 of the EK-TM4C123GXL Firmware Package. // //***************************************************************************** #include #include #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "driverlib/debug.h" #include "driverlib/fpu.h" #include "driverlib/gpio.h" #include "driverlib/interrupt.h" #include "driverlib/pin_map.h" #include "driverlib/rom.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "driverlib/i2c.h" #include "sensorlib/i2cm_drv.h" #include "sensorlib/mpu6050.h" #include "sensorlib/hw_mpu6050.h" //***************************************************************************** // // Define pin to LED color mapping. // //***************************************************************************** //***************************************************************************** //***************************************************************************** // // The error routine that is called if the driver library encounters an error. // //***************************************************************************** #ifdef DEBUG void __error__(char *pcFilename, uint32_t ui32Line) [ ] #endif //***************************************************************************** // // Main 'C' Language entry point. Toggle an LED using TivaWare. // See http://www.ti.com/tm4c123g-launchpad/project0 for more information and // tutorial videos. // //***************************************************************************** //mpu6050.h #ifndef _MPU6050_H #define _MPU6050_H //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //接口定义 //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& #define MPU_IO_RCC RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO #define IIC_1_RCC RCC_APB1Periph_I2C1 #define MPU_PORT GPIOB #define SCL1_PIN GPIO_Pin_6 #define SDA1_PIN GPIO_Pin_7 //**************************************** // 定义MPU6050 内部地址 //**************************************** #define SMPLRT_DIV 0x19 //陀螺仪采样率,典型值:0x07(125Hz) #define CONFIG 0x1A //低通滤波频率,典型值:0x06(5Hz) #define GYRO_CONFIG 0x1B //陀螺仪自检及测量范围,典型值:0x18(不自检,2000deg/s) #define ACCEL_CONFIG 0x1C //加速计自检、测量范围及高通滤波频率,典型值:0x01(不自检,2G,5Hz) #define ACCEL_XOUT_H 0x3B #define ACCEL_XOUT_L 0x3C #define ACCEL_YOUT_H 0x3D #define ACCEL_YOUT_L 0x3E #define ACCEL_ZOUT_H 0x3F #define ACCEL_ZOUT_L 0x40 #define TEMP_OUT_H 0x41 #define TEMP_OUT_L 0x42 #define GYRO_XOUT_H 0x43 #define GYRO_XOUT_L 0x44 #define GYRO_YOUT_H 0x45 #define GYRO_YOUT_L 0x46 #define GYRO_ZOUT_H 0x47 #define GYRO_ZOUT_L 0x48 #define PWR_MGMT_1 0x6B //电源管理,典型值:0x00(正常启用) #define WHO_AM_I 0x75 //IIC 地址寄存器(默认数值0x68,只读) #define SlaveAddress 0x68 //IIC 写入时的地址字节数据,+1 为读取 #define LSB_g 16384 //LSB/g 即16384=g=9.8m/(S*S) #define deg_LSB 10/164 //deg/LSB #define LSB_t 340 //l***/℃ void write_byte(uint8_t REG_Address,uint8_t REG_data); uint32_t read_byte(uint8_t REG_Address); void InitMPU6050(void); uint32_t getdate(uint8_t REG_Address); #endif //mpu6050.c 文件 //#include"mpu6050.h" void write_byte(uint8_t REG_Address,uint8_t REG_data) [ // I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_START); I2CMasterSlaveAddrSet(I2C3_BASE, SlaveAddress, false); I2CMasterDataPut(I2C3_BASE, REG_Address); I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_START); I2CMasterDataPut(I2C3_BASE, REG_data); I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH); while(I2CMasterBusBusy(I2C3_BASE)) [ ] I2CMasterDataPut(I2C3_BASE, REG_data); I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH); while(I2CMasterBusBusy(I2C3_BASE)) [ ] I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_STOP); ] uint32_t read_byte(uint8_t REG_Address) [ uint32_t REG_data; I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_START); I2CMasterSlaveAddrSet(I2C3_BASE, SlaveAddress, false); I2CMasterDataPut(I2C3_BASE, REG_Address); I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_START); I2CMasterSlaveAddrSet(I2C3_BASE, SlaveAddress, true); I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE); while(I2CMasterBusBusy(I2C3_BASE)) [ ] REG_data=I2CMasterDataGet(I2C3_BASE); I2CSlaveACKOverride(I2C3_BASE,true); I2CSlaveACKValueSet(I2C3_BASE,false); I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_STOP); return REG_data; ] void InitMPU6050(void) [ write_byte(PWR_MGMT_1, 0x00); //解除休眠状态 write_byte(SMPLRT_DIV, 0x07); write_byte(CONFIG, 0x06); write_byte(GYRO_CONFIG, 0x18); write_byte(ACCEL_CONFIG, 0x01); ] uint32_t getdate(uint8_t REG_Address) [ uint32_t geted_date=0; geted_date=read_byte(REG_Address)<<8; geted_date|=read_byte(REG_Address+1); return geted_date; ] //mian.c 部分内容 uint32_t data_x,data_y,data_z; int main(void) [ SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); GPIOPinConfigure(GPIO_PD0_I2C3SCL); GPIOPinConfigure(GPIO_PD1_I2C3SDA); GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0); GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1); // // Initialize Master and Slave // I2CMasterInitExpClk(I2C3_BASE, SysCtlClockGet(), true); InitMPU6050(); while(1) [ write_byte(PWR_MGMT_1, 0x00); ] ] 我用以上代码进行I2C通信,用示波器查看结果,发现在给出开始信号后,传输了设备地址0x68+写信号后有一个ack,然后跳过寄存器值,直接传输数据0x00,然后就是结束信号,好像是两次给MDR寄存器赋值导致覆盖了,随后重复这个过程。那到底该怎么控制给从机传输的数据啊,数据手册只给出了MCS寄存器传输接收的值,但没有详细介绍到底怎么控制 ,给的参考程序也都有各种问题。 |
|
相关推荐
3 个讨论
|
|
只有小组成员才能发言,加入小组>>
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
661 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
587 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1041 浏览 1 评论
720 浏览 0 评论
普中科技F28335开发板每次上电复位后数码管都会显示,如何熄灭它?
516 浏览 1 评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
151浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
116浏览 14评论
在使用3254进行录音的时候出现一个奇怪的现象,右声道有吱吱声,请教一下,是否是什么寄存器设置存在问题?
120浏览 13评论
TLV320芯片内部自带数字滤波功能,请问linein进来的模拟信号是否是先经过ADC的超采样?
118浏览 12评论
TPA6304-Q1: TPA6304 两片公用一组I2C的话,其中一片配置不成功怎么办
161浏览 10评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-19 22:36 , Processed in 0.952598 second(s), Total 71, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号