Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2C not working on P0_09 and P0_10 #418

Open
arnobert opened this issue Feb 15, 2023 · 1 comment
Open

I2C not working on P0_09 and P0_10 #418

arnobert opened this issue Feb 15, 2023 · 1 comment

Comments

@arnobert
Copy link

arnobert commented Feb 15, 2023

Found that using those two pins for I2C lead to an infinite loop in twim / fn wait().
Both pins do not toggle and stay high, on nRF52840 dongle.

Is this related to their secondary function (NFC antenna)? Or have I overlooked something?
Thanks!

@eflukx
Copy link

eflukx commented Jul 21, 2023

Yep, you have to "unlock" the pins for normal IO functionality. You may try the code below :)

/// "Unprotect" NFC pins and enable as GPIO pins (stored in FLASH, needs reset after change)
/// Returns `true` if setting was changed

pub fn nfc_pins_as_gpio(periphs: &pac::Peripherals) -> bool {
    if periphs.UICR.nfcpins.read().protect().bit_is_set() {
        let nvmc = &periphs.NVMC;
        assert!(!nvmc.config.read().wen().is_een()); // write + erase is forbidden!

        nvmc.config.write(|w| w.wen().wen());
        unsafe { periphs.UICR.nfcpins.write(|w| w.bits(0)) };
        nvmc.config.reset();

        true
    } else {
        false
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants