Skip to content

Digital read can return before the default pull down affects the value returned #512

@martinwork

Description

@martinwork

Arising from support ticket https://support.microbit.org/helpdesk/tickets/93871 (private)

When an unconnected croc lead is attached to P0/1/2 the first digital read sees high rather than low.

In this example the first A press shows a sad face (NB: testing P1, though P0 and P2 are the same)
https://makecode.microbit.org/_bLeeKP2HohFw
Image

This is more like the ticket example: https://makecode.microbit.org/_bAPWrzXghiu1

C++ example (press A): test-digitalread.zip

When tested with just one croc lead, it's enough to move setPull before setting input mode, but with a chain of croc leads. a longer delay seems to be required:: e.g. target_wait(1) after setPull.
https://github.com/lancaster-university/codal-nrf52/blob/master/source/NRF52Pin.cpp#L291

I haven't found an example that triggers a wrong value except the very first after reset. V1 is OK.

This is related, though maybe not the actual explanation!
https://devzone.nordicsemi.com/f/nordic-q-a/36881/best-practice---delay-between-setting-pin-as-input-with-pull-up-pull-down-and-reading-the-pin

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