Skip to content

Bug in readRegister() – Incorrect register byte count in readRegisters call #11

@justkozi

Description

@justkozi

Bug in readRegister() – Incorrect register byte count in readRegisters call

Description

While working with the TMAG5273 sensor on the Raspberry Pi Pico using your library, I encountered a communication issue which I traced back to the readRegister() function.

Problem

The current implementation reads 2 bytes from a register instead of the expected 1 byte, which leads to incorrect behavior on devices with strict I2C read handling like the Pi Pico.

uint8_t TMAG5273::readRegister(uint8_t regAddress)
{
    uint8_t regVal = 0;
    readRegisters(regAddress, &regVal, 2);  // <-- Incorrect byte count
    return regVal;
}

Fix

uint8_t TMAG5273::readRegister(uint8_t regAddress)
{
    uint8_t regVal = 0;
    readRegisters(regAddress, &regVal, 1);  // <-- Should read only 1 byte
    return regVal;
}

Impact

  • Causes data corruption or bus errors on microcontrollers with strict I2C behavior
  • Verified specifically on Raspberry Pi Pico (RP2040)

Please consider updating the library accordingly. Let me know if a pull request is preferred—I’d be happy to submit one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions