Skip to content

Hang if no pull-up present #97

Open

Description

@xross

The lib includes a wait on SCL high, this is either an event or a polling loop, dependent on implementation.

If this is called on a system where the pull up isn't present then the project can hang forever - not ideal.

If would be better if this error was detected and reported to the developer.

This could be done with timeouts or a simple check for pull-up present at init time.

Real world use case is running USB Audio project on a custom board - we ideally don't want it to hang.

Activity

  1. XMOS-JoeG commented on Oct 1, 2024

    @XMOS-JoeG

    Example:

    p_scl when pinseq(1) :> void;

    in release_clock_and_wait function. Yes function should wait until clock goes high, but not forever!

    Should timeout and report error or similar.

  2. xross commented on Oct 1, 2024

    @xross
    ContributorAuthor

    Polling loop example:

    while (!(val & SCL_HIGH)) {

  3. xross commented on Jul 9, 2025

    @xross
    ContributorAuthor

    Suggested implementation:

    • Add check for pull ups on both SDA and SCL lines at startup in i2c_master() and set an bus error variable appropriately
      • This could be done multiple ways:
        • drive low then high-z and see how long it takes to read 1
        • check for input 1 for quite some period of time (i.e. avoid glitching on floating inputs)
    • Extend i2c_res_t for error conditions (could have multiple errors cases for SCL or SDA pull ups missing for example)
    • Modify read() and write() such if bus error var err set they perform no action but return error code
    • Update read_reg() and write_reg() to inspect and respect return codes from read() and write()
    • Do something appropriate with i2c_regop_res_t return value from read_reg() and write_reg()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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