本帖最后由 zxykklt 于 2017-9-29 08:24 编辑
最近研究LIS2 DH12,用IIC补充ST的驱动代码,通过方式一写可以正确将函数IIC_Read_Byte()的返回值传给指针Bufp所指的内存,但是通过方式二指针Bufp指向的位置不能被赋值,已经无助了,各位谁知道这是怎么回事???
方式一:
[mw_shl_code=c,true]status_t LIS2DH12_ACC_ReadReg(void *handle, u8_t Reg, u8_t *Bufp, u16_t len)
{
//To be completed with either I2c or SPI writing function
//i.e.: SPI_Mems_Write_Reg(Reg, Data);
//I2Cx_Write(Bufp, LSM6DS3H_ACC_GYRO_I2C_ADDRESS, Reg, len); //[Example]
u8_t Data;
IIC_Start();
IIC_Send_Byte(0x30);
IIC_Wait_Ack();
IIC_Send_Byte(Reg);
IIC_Wait_Ack();
IIC_Start();
IIC_Send_Byte(0x31);
IIC_Wait_Ack();
Data=IIC_Read_Byte(0);
// *Bufp=IIC_Read_Byte(0);
IIC_Stop();
Bufp=&Data;
return MEMS_SUCCESS;
}[/mw_shl_code]
方式二:
[mw_shl_code=c,true]status_t LIS2DH12_ACC_ReadReg(void *handle, u8_t Reg, u8_t *Bufp, u16_t len)
{
//To be completed with either I2c or SPI writing function
//i.e.: SPI_Mems_Write_Reg(Reg, Data);
//I2Cx_Write(Bufp, LSM6DS3H_ACC_GYRO_I2C_ADDRESS, Reg, len); //[Example]
// u8_t Data;
IIC_Start();
IIC_Send_Byte(0x30);
IIC_Wait_Ack();
IIC_Send_Byte(Reg);
IIC_Wait_Ack();
IIC_Start();
IIC_Send_Byte(0x31);
IIC_Wait_Ack();
// Data=IIC_Read_Byte(0);
*Bufp=IIC_Read_Byte(0);
IIC_Stop();
// Bufp=&Data;
return MEMS_SUCCESS;
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
0x70不对么?不是你要读取的ID?
一周热门 更多>