0
我一直在测试ADXL345加速计,能够获取设备ID以检查它是否连接正确。现在我试图在不同的轴上获得加速度,因为我不知道寄存器地址不是由于某种原因发送的,所以我无法完成它。寄存器地址在TM4C123GH6PM板上不使用I2C发送
根据该加速度计的数据表中,为了写入一字节:
使用的代码:
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();
}
}
}
测试与逻辑分析仪,结果如下:
正如你所看到的,所有的都被发送,但寄存器地址。你能帮我找到错误吗?
感谢, 哈维尔