【发布时间】:2017-05-11 01:17:06
【问题描述】:
我一直在使用 ADXL345 加速度计进行测试,能够获取设备 ID 以检查它是否正确接线。现在我正在尝试获得不同轴的加速度,但由于某种我不知道的原因没有发送寄存器地址,所以我无法完成它。
根据加速度计的datasheet,为了写一个字节:
使用的代码:
void initialize_accelerometer()
{
I2C0_MSA_R |=0x000000A6; //Specify the slave address of the master and that the next operation is a Transmit or write
I2C0_MDR_R=0x2D; //Register address, this is the data not sent
I2C0_MCS_R=0x00000003; // (START, RUN);
while(I2C0_MCS_R&I2C_MCS_BUSBSY){};
if((I2C0_MCS_R&I2C_MCS_ERROR)==0)
{
I2C0_MDR_R=0x08; //Data -> Set power control to measure
I2C0_MCS_R=0x00000005; // (RUN, STOP);
if((I2C0_MCS_R&I2C_MCS_ERROR)==0)
{
set_data_format();
}
}
}
用逻辑分析仪测试,结果如下:
如您所见,除了注册地址外,所有内容都已发送。你能帮我找出错误吗?
谢谢, 哈维尔
【问题讨论】:
标签: accelerometer i2c texas-instruments