//==========MMA8451 寄存器地址==================// #define MMA8451_DSR 0x00 // Data Status Register #define MMA8451_XOUT 0x01 // 14-bit output value X #define MMA8451_YOUT 0x03 // 14-bit output value Y #define MMA8451_ZOUT 0x05 // 14-bit output value Z #define MMA8451_CFG 0x0E // XYZ_DATA_CFG Register [1:0]scale value range #define MMA8451_SR 0x29 // Auto-Wake/Sleep and #define MMA8451_CR1 0x2A // System Control 1 Registe //[5:3]bits select the Output Data Rate (ODR) for acceleration samples //=========MMA8451 功能参数==================// #define MMA8451_MODE 0x11 // DR = 50 Hz F_READ=0 ACTIVE=1 #define MMA8451_SCAL 0x00 // 0x00 2g 0x01 4g 0x10 8g #define MMA8451_WADDR 0X38 //write address [7:1]=0x1c [0]=0 [7:0]=0x38 #define MMA8451_RADDR 0X39 //read address [7:1]=0x1c [0]=1 [7:0]=0x39 下面这个函数该如何用 求助 uint8_t IIC_MMA8451_ReadAddr(uint8_t slave_add, uint8_t Addr, uint8_t *rece_data, uint16_t n) { uint8_t receive_da,check; uint16_t i=0; uint8_t *rece_data_buff ; rece_data_buff = rece_data ; IIC_MMA8451_Start(); //ST IIC_MMA8451_SendByte(MMA8451_WADDR); // MMA8451_WADDR IIC_MMA8451_Delay_1us(MMA8451_DELAY); // 延时1us check =IIC_MMA8451_Check_ACK(); if(check == 1) { return IICEorr ; } IIC_MMA8451_SendByte(Addr); //REGISTER ADDR IIC_MMA8451_Delay_1us(MMA8451_DELAY); // 延时1us check =IIC_MMA8451_Check_ACK(); if(check == 1) { return IICEorr ; } IIC_MMA8451_Start(); IIC_MMA8451_SendByte(slave_add); IIC_MMA8451_Delay_1us(MMA8451_DELAY); // 延时1us check =IIC_MMA8451_Check_ACK(); if(check == 1) { return IICEorr ; } for(;n > 1;n--) { receive_da=IIC_MMA8451_ReceiveByte(); rece_data_buff[i++]=receive_da; IIC_MMA8451_Slave_ACK(); // 收到一个字节后发送一个应答位 } receive_da=IIC_MMA8451_ReceiveByte(); rece_data_buff[i++]=receive_da; IIC_MMA8451_Slave_NOACK(); // 收到最后一个字节后发送一个非应答位 IIC_MMA8451_Stop(); return IICOK; } |
欢迎光临 智能车制作 (http://111.231.132.190/) | Powered by Discuz! X3.2 |