讀取和寫入的邏輯分析儀波形如上圖
代碼如下
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的最新庫函數。