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

Arduino INPUT_PULLUP on pin9 of genericSAMD11C14 #37

Open
roberthart56 opened this issue Apr 9, 2020 · 2 comments
Open

Arduino INPUT_PULLUP on pin9 of genericSAMD11C14 #37

roberthart56 opened this issue Apr 9, 2020 · 2 comments

Comments

@roberthart56
Copy link

When using Arduino IDE, setting INPUT_PULLUP on pin 9 of the generic SAMD11C14A leaves pin 9 floating, but pulls up pin 8. Other pins seem to work as expected.

@ghost
Copy link

ghost commented Aug 18, 2022

Cursed workaround:

re-run pinMode() immediately before calling digitalRead(), (or, I suspect, just after every call to Serial.print() and probably other Serial methods I haven't enumerated). From the digging i did, it appears pin 9 is set up as a serial port, so I'm guessing what happens is, every time a Serial method is called, it sets the PMUXEN bit in the PINCFG register for that pin (see datasheet section 22.8.13 for that register description). The only reason it keeps working as an input is that it appears to be mapped to a serial input. Sadly I don't know enough about Arduino to know how to properly fix this, perhaps disabling the right serial port would help.

Slight speed optimization over pinMode() workaround if it matters: to reset the PMUXEN bit, you can run this instead and save on the other register accesses pinMode() does.

PORT->Group[0].PINCFG[9].reg=(uint8_t)(PORT->Group[0].PINCFG[9].reg & B11111110);

This reads in the current PINCFG register for pin 9, sets the PMUXEN bit to 0, and writes it back out. If at the time of calling you know for a fact it's in INPUT_PULLUP, then this would save on that read and just write out a fixed value:

PORT->Group[0].PINCFG[9].reg=(uint8_t)B00000110;

This still isn't great though, because the pullup is still being turned off every time Serial.print() is called. Depending on what that pin is hooked up to, periodically glitching the pullup off and back on again (especially if you turn it back on right before reading the input) could cause problems. a more permanent workaround (or an actual fix) is still needed.

@ictq-oy
Copy link

ictq-oy commented Nov 4, 2022

This is because pin 8 and pin 9 are designated as LEDs to be used for Serial or USB in the variant.h of Generic_D11C14A.

If you edit variant.h and comment out the relevant line, you can use them as normal I/O. Specifically, it is around line 131 to 144.

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