Skip to content

Corrupted sensor reports when packets are read in 32-byte I2C chunks (ESP32-S3) #32

Open

Description

@ssantosramon

When running the modified "Linear Accelerometer" example with the sensor stationary, it is possible to see the outliers in the acceleration on line 9:

  1. acx_unf:00.004, acy_unf:00.031, acz_unf:00.051, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.791
  2. acx_unf:00.043, acy_unf:00.008, acz_unf:00.012, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.801
  3. acx_unf:00.023, acy_unf:00.016, acz_unf:00.004, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.810
  4. acx_unf:00.004, acy_unf:00.012, acz_unf:00.012, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.825
  5. acx_unf:00.004, acy_unf:00.012, acz_unf:00.008, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.840
  6. acx_unf:00.012, acy_unf:00.020, acz_unf:00.008, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.855
  7. acx_unf:00.016, acy_unf:00.000, acz_unf:00.004, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.861
  8. acx_unf:00.016, acy_unf:00.008, acz_unf:00.043, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.876
  9. acx_unf:00.016, acy_unf:122.031, acz_unf:49.012, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.888
  10. acx_unf:00.004, acy_unf:00.008, acz_unf:00.004, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.897
  11. acx_unf:00.023, acy_unf:00.016, acz_unf:00.008, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.906
  12. acx_unf:00.016, acy_unf:00.008, acz_unf:00.008, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.927
  13. acx_unf:00.004, acy_unf:00.035, acz_unf:00.031, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.936
  14. acx_unf:00.023, acy_unf:00.000, acz_unf:00.004, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.957
  15. acx_unf:00.016, acy_unf:00.000, acz_unf:00.012, Roll:00.000, Pitch:00.000, Yaw:00.000, trust accel:3, Delta (μs):40.966

Description: With SH2_LINEAR_ACCELERATION and SH2_GAME_ROTATION_VECTOR enabled together (5 ms), SHTP packets are ~100 bytes and are read in ~4 chunks because _maxBufferSize = 32. Occasionally an accelerometer report has its Y/Z bytes replaced by the header of the following report. Example: acy = 122.031, acz = 49.012 while stationary, which is raw 08 7A 03 31 = [reportId 0x08][seq][status 0x03][delay]. Timestamps of those reports are also wrong (seq/delay reset, no 0xFB base timestamp report). Status stays at 3, so it can't be filtered by accuracy.

Observation: setting _maxBufferSize = 128 (ESP32's Wire buffer size) eliminated the problem, so the multi-chunk reassembly in i2chal_read() is the suspect. I haven't identified the exact mechanism.

Suggestion: default _maxBufferSize to I2C_BUFFER_LENGTH when the platform provides it, and review the chunk-continuation logic.

Environment: ESP32-S3, Arduino core X.Y.Z, 100 kHz, external 3.3k pull-ups.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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