本次解析的是LPS22HH 芯片, 接口还是IIC, 驱动还是按照原来的, 先实验读ID;
uint8_t LPS22HH_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_LPS = %X\r\n",LPS22HH_Read_Date(LPS22HH_ADD, 0x0F));
此内容由EEWORLD论坛网友DavidZH原创,如需转载或用于商业用途需征得作者同意并注明出处