完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File Uint16 *ExRamStart = (Uint16 *)0x100000; #define DELAY_US(A) DSP28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L) void Initi2C(void); Uint16 ReadData(Uint16 *RamAddr, Uint16 RomAddress, Uint16 number); Uint16 WriteData(Uint16 *Wdata, Uint16 RomAddress, Uint16 number); void initmpu(); Uint16 I2C_xrdy(); Uint16 I2C_rrdy(); Uint16 i; //************************************************************* #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 0xD0 //IIC写入时的地址字节数据,+1为读取 //************************************************************************************* Uint16 a=0x00,b=0x07,c=0x06,d=0x18,e=0x01,f=0x80; Uint16 dat1[8]={0,0,0,0,0,0,0,0}; //Uint16 databuff[]; void main(void) { // Uint16 dat[]={ 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88}; // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the DSP2833x_SysCtrl.c file. InitSysCtrl(); // Step 2. Initalize GPIO: // This example function is found in the DSP2833x_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // Skipped for this example InitXintf16Gpio(); //zq InitI2CGpio(); InitI2C(); // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize the PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the DSP2833x_PieCtrl.c file. InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000; LedReg = 0xFF; DELAY_US(1500); initmpu(); // WriteData(dat,0x60,8); DELAY_US(10000); // ReadData(dat1,0x60,8); for(; ;) { ReadData(dat1,ACCEL_ZOUT_L,2); } } void initmpu() { DELAY_US(1500); WriteData(&e,PWR_MGMT_1,2); DELAY_US(1500); WriteData(&a,PWR_MGMT_1,2); WriteData(&a,PWR_MGMT_1,2); WriteData(&b,SMPLRT_DIV,2); WriteData(&c,CONFIG,2); WriteData(&d,GYRO_CONFIG,2); } Uint16 WriteData(Uint16 *Wdata, Uint16 RomAddress, Uint16 number) { Uint16 i; if (I2caRegs.I2CSTR.bit.BB == 1) { return I2C_BUS_BUSY_ERROR; } while(!I2C_xrdy()); I2caRegs.I2CSAR = SlaveAddress; I2caRegs.I2CCNT = number + 1; I2caRegs.I2CDXR = RomAddress; I2caRegs.I2CMDR.all = 0x6E20; for (i=0; i while(!I2C_xrdy()); I2caRegs.I2CDXR = *Wdata; // Wdata++; if (I2caRegs.I2CSTR.bit.NACK == 1) return I2C_BUS_BUSY_ERROR; } return I2C_SUCCESS; } Uint16 ReadData(Uint16 *RamAddr, Uint16 RomAddress, Uint16 number) { Uint16 i,Temp; if (I2caRegs.I2CSTR.bit.BB == 1) { return I2C_BUS_BUSY_ERROR; } while(!I2C_xrdy()); I2caRegs.I2CSAR = SlaveAddress; I2caRegs.I2CCNT = 1; I2caRegs.I2CDXR = RomAddress; I2caRegs.I2CMDR.all = 0x2620; if (I2caRegs.I2CSTR.bit.NACK == 1) return I2C_BUS_BUSY_ERROR; DELAY_US(500); while(!I2C_xrdy()); I2caRegs.I2CSAR = SlaveAddress; I2caRegs.I2CCNT = number; I2caRegs.I2CMDR.all = 0x2C20; if (I2caRegs.I2CSTR.bit.NACK == 1) return I2C_BUS_BUSY_ERROR; for(i=0;i while(!I2C_rrdy()); Temp = I2caRegs.I2CDRR; if (I2caRegs.I2CSTR.bit.NACK == 1) return I2C_BUS_BUSY_ERROR; *RamAddr = Temp; RamAddr++; } i=0; return I2C_SUCCESS; } Uint16 I2C_xrdy() { Uint16 t; t = I2caRegs.I2CSTR.bit.XRDY; return t; } Uint16 I2C_rrdy() { Uint16 t; t = I2caRegs.I2CSTR.bit.RRDY; return t; } //=========================================================================== // No more. //=========================================================================== 程序如上,为什么我收到的数据 一直是255,求解答 |
|
相关推荐
4个回答
|
|
那应该是I2C的协议还是不对吧
|
|
|
|
|
|
|
|
自己顶一下 自己顶一下 自己顶一下
|
|
|
|
楼主,最后怎么解决的?我用正点原子的程序,读出来3个都是-1
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
嵌入式DSP教学实验箱操作教程:2-20 数模转换实验(模拟SPI总线输出电压值)
657 浏览 0 评论
目前在2837x系列用的最多的、性能最好、性价比最高的是哪一款?
434 浏览 0 评论
国产嵌入式DSP教学实验箱_操作教程:22-AD采集DA输出实验(采集输出正弦波)
1627 浏览 0 评论
2360 浏览 0 评论
使用CCS6.0尝试给TMS320VC5502进行配置的时候找不到对应芯片的选项,该怎么麽办呀?
2336 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-3-29 14:53 , Processed in 0.484786 second(s), Total 75, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 深圳华秋电子有限公司
电子发烧友 (电路图) 粤公网安备 44030402000349 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号