(Apologies if you’ve already seen this question on StackExchange)
I'm working on a demo program for which I want to use minimal resources: all I need is one LED and one pushbutton.
I'd very much like to use on-board resources. The user LED (PB27) is fine (I'd have liked one more, but there it is).
I read in the datasheet that the ERASE button can be used as an input (PC0) provided that I clear the SYSIO12 bit in the System I/O Configuration Register CCFG_SYSIO.
I find that if I do this I can push the ERASE button without erasing flash (!), but PC0 always reads as 0 (even if I enable pullup; ought to be already enabled, you'd think).
I should add that PC1 works just fine.
Has anyone else got ERASE => PC0 to work? is there documentation I've missed? (in ASF, some of the other boards in sam/applications/getting_started/ disable the ERASE button, but not this one).
Did you power PIOC in your code ?
ard_newbie:
Did you power PIOC in your code ?
Yes (as I said, PC1 works as expected).
(I don’t think I can usefully post the code, since it’s in Ada: however, if interested, see here)
When PC0 is used as a GPIO, you have to clear SYSIO12 bit in CCFG_SYSIO.
void setup() {
PMC->PMC_PCER0 = PMC_PCER0_PID13; // PIOC power ON
MATRIX->CCFG_SYSIO = 0; // PC0 used as GPIO
PIOC->PIO_PUDR = ~0UL;
PIOC->PIO_PUER = PIO_PUER_P0; // PC0 pull up enable
// You can't use attachinterrupt() with PC0 since PC0 has no pin number
}
void loop() {
uint32_t status;
status = PIOC->PIO_PDSR;
if ((status & 1ul) == 0)
{
// Do something if Erase button is pressed
}
}
Note that once you have cleard SYSIO12 in CCFG_SYSIO, you can't upload a new sketch for 5 minutes. Before uploading a new sketch, power down your board for 5 minutes.
Thanks for that, but that’s what I’m already doing, and as I said it (not the SYSIO12 part, of course) works for PC1.
Except I don’t disable pullup on all the PC pins (PIOC->PIO_PUDR = ~0UL;) - is it necessary?
Where does the 5 minutes come from? This might be the explanation for my troubles.