飞思卡尔三轴加速度传感器MMA7455,是通过IIC和SPI同单片机通讯的,不用什么AD转换了,好像咱坛子里前些日子有个活动DIY三轴加速传感器。
上资料:
HQ745x--mma7455数字三轴加速度模块中文手册.pdf
(511.65 KB, 下载次数: 672)
我元旦利用两天的空闲时间调通了MMA7455。用的是IIC。转动板子X轴数字从0变到70左右又从70左右变回。
现在我把注意事项说下:
一、IIC的地址一定要正确,速率快点慢点我觉得不太重要。
二、中断IIC一定要添上如下,在Startup.s
DCD IntDefaultHandler ; SSI
extern I2C_ISR
DCD I2C_ISR ; I2C
DCD IntDefaultHandler ; PWM Fault
DCD IntDefaultHandler ; PWM Generato
下面是程序注释:
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_8MHZ); //使用外部时钟
I2CInit(100000, 1);//I2C初始化
RIT128x96x4Init(1000000);//液晶显示初始化
RIT128x96x4StringDraw("mma7455L", 30, 24, 15);
sendbuff[0] = 0x05;//设三轴加速器为2G动态测试
ISendStr(0x3A, 0x16, 1, &sendbuff[0], 1); //写命令
IRcvStr(0x3B, 0x16, 1, &receivebuff[0], 1); //测试写的对不对
test = receivebuff[0];
while(!test); //不对就死在这里
while (1)
{
IRcvStr(0x3B, 0x06, 1, &receivebuff[1], 1); //读X轴
delay(10000);
x[0]=receivebuff[1]/100%10+0x30;
x[1]=receivebuff[1]/10%10+0x30;
x[2]=receivebuff[1]%10+0x30;
x[3]=0;
IRcvStr(0x3B, 0x07, 1, &receivebuff[2], 1); //读Y轴
delay(10000);
y[0]=receivebuff[2]/100%10+0x30;
y[1]=receivebuff[2]/10%10+0x30;
y[2]=receivebuff[2]%10+0x30;
y[3]=0;
IRcvStr(0x3B, 0x08, 1, &receivebuff[3], 1); //读Z轴
delay(10000);
z[0]=receivebuff[3]/100%10+0x30;
z[1]=receivebuff[3]/10%10+0x30;
z[2]=receivebuff[3]%10+0x30;
z[3]=0;
RIT128x96x4StringDraw("X:", 15, 40, 15);
RIT128x96x4StringDraw(&x[0], 30, 40, 15);
RIT128x96x4StringDraw("Y:", 15, 48, 15);
RIT128x96x4StringDraw(&y[0], 30, 48, 15);
RIT128x96x4StringDraw("Z:", 15, 56, 15);
RIT128x96x4StringDraw(&z[0], 30, 56, 15);
delay(10000);
delay(1000000);
上程:
mma7455.zip
(150.94 KB, 下载次数: 318)
上照片
[
本帖最后由 ddllxxrr 于 2011-1-3 21:37 编辑 ]