今天解析LIS2DW12, 模拟IIC接口,先验证ID:
uint8_t LIS2DW12_Read_Date(uint8_t SlaveAddress, uint8_t RegAddress)
{
uint8_t recvDate;
uint8_t succ, stime=0;
I2C_Start();
succ = I2C_Send_Byte(SlaveAddress & 0xfe);
while((succ !=1)&&(stime<3))
{
I2C_Stop();
I2C_Start();
succ = I2C_Send_Byte(SlaveAddress & 0xfe); //写
stime++;
}
I2C_Send_Byte(RegAddress);
I2C_Start();
I2C_Send_Byte(SlaveAddress | 0x01); //读
recvDate = I2C_Read_Byte(1); //NACK
I2C_Stop();
return recvDate;
}
printf("PID_LSM2 = %X\r\n",LIS2DW12_Read_Date(LIS2DW12_ADD, 0x0F));
此内容由EEWORLD论坛网友DavidZH原创,如需转载或用于商业用途需征得作者同意并注明出处
补充内容 (2019-9-24 20:47):
附上工程