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

How to add Pin Change Interrupts #235

Closed
Xychic opened this issue Jan 17, 2022 · 1 comment
Closed

How to add Pin Change Interrupts #235

Xychic opened this issue Jan 17, 2022 · 1 comment
Labels
question Further information is requested

Comments

@Xychic
Copy link

Xychic commented Jan 17, 2022

I am trying to attach a pin change interrupt to pin D2 of an Arduino Nano.

From reading the code I think I need a function called PCINT0, and need to call avr_device::interrupt::enable(); and from reading the data sheet for the ATmega328P I believe I need to set bit 0 of the PCICR to 1 and bit 2 of PCMSK2 to 1 however I can't figure out how to control those registers.

My interrupt function is below

#[avr_device::interrupt(atmega328p)]
fn PCINT0() {
    PCINT0_STORE.store(true, atomic::Ordering::SeqCst);
}
@Xychic Xychic changed the title Pin Change Interrupts How to add Pin Change Interrupts Jan 17, 2022
@Xychic
Copy link
Author

Xychic commented Jan 17, 2022

After spending the last 2 hours going through docs again I have it working.

The bit of code needed to control the registers is

peripherals.EXINT.pcicr.write(|w| unsafe { w.bits(0b100) });
peripherals.EXINT.pcmsk2.write(|w| unsafe { w.bits(0b100) });

and as pin D2 is in PCIE2 the interrupt function should be called PCINT2

@Xychic Xychic closed this as completed Jan 17, 2022
@Rahix Rahix added the question Further information is requested label Jan 17, 2022
This was referenced Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants