读取和写入的逻辑分析仪波形如上图
代码如下
void QMC5883_Write(u8 addr, u8 data)
{
tls_i2c_write_byte(QMC5883_SlaveAddress, 1);
tls_i2c_wait_ack();
tls_i2c_write_byte(addr, 0);
tls_i2c_wait_ack();
tls_i2c_write_byte(data, 0);
tls_i2c_wait_ack();
tls_i2c_stop();
}
u8 QMC5883_Read_Byte(u8 addr)
{
uint8_t data;
tls_i2c_write_byte(QMC5883_SlaveAddress, 1);
tls_i2c_wait_ack();
tls_i2c_write_byte(addr, 0);
tls_i2c_wait_ack();
tls_i2c_write_byte(QMC5883_SlaveAddress+1, 0);
tls_i2c_wait_ack();
data = tls_i2c_read_byte(0, 1);
return data;
}
写入可以正常产生停止位,但是读取无法产生,使用的是w800的最新库函数。