Teensy 4.0 I2C sending too many bytes.

Status
Not open for further replies.
Im working on a project and trying to get a QMC5883 sensor running. This worked before but for some reason im getting issues now. I dont think i changed anything since it was last running.
Anyway the issue comes up when trying to write to the sensors registers, im only writting one byte (max 2) and for some reason its (according to return value of .endTransmittion(true)) sending 4 bytes.

Code:

This function is member of a class that contains a pointer to the Wire object for I2C (bus_ member) and also the address of the device (address_ member)

Code:
bool writeBytes(uint32_t writeRegister, const void* writeData, uint32_t numberBytes, bool release = true) {

    Serial.println(String("Input register: ") + writeRegister + ", num Bytes: " + numberBytes + ", release: " + release); // For debugging

    bus_->beginTransmission((uint8_t)address_);

    bus_->write((uint8_t*)&writeRegister, 1);
    bus_->write((uint8_t*)writeData, numberBytes);

    uint32_t sentBytes = bus_->endTransmission(release);

    Serial.println(String("Sent: ") + sentBytes); // For debugging

    return sentBytes == numberBytes;

}

Serial output:

Code:
Input register: 10, num Bytes: 1, release: 1
Sent: 4

Of course this will always return false as something was not right when sending the data.
 
Status
Not open for further replies.
Back
Top