Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Teensy 4.0 I2C sending too many bytes.

  1. #1
    Junior Member
    Join Date
    Dec 2019

    Teensy 4.0 I2C sending too many bytes.

    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.


    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)

    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_->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:

    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.

  2. #2
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    According to the documentation endTransmission does not return the number of bytes sent, rather it returns a non zero number if there is an error.
    The documentation is here:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts