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

External interrupts for mega2560 #393

Closed
ZettaScript opened this issue Jan 17, 2023 · 4 comments
Closed

External interrupts for mega2560 #393

ZettaScript opened this issue Jan 17, 2023 · 4 comments

Comments

@ZettaScript
Copy link

ZettaScript commented Jan 17, 2023

The following code works for Atmega328:

let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);

dp.EXINT.eicra.modify(|_, w| w.isc0().bits(INT_CHANGE));
dp.EXINT.eimsk.modify(|_, w| w.int0().set_bit());
dp.EXINT.eicra.modify(|_, w| w.isc1().bits(INT_CHANGE));
dp.EXINT.eimsk.modify(|_, w| w.int1().set_bit());

However it does not compile for Atmega2560:

error[E0599]: no method named `int0` found for mutable reference `&mut arduino_hal::pac::exint::eimsk::W` in the current scope
   --> src/main.rs:149:34
    |
149 |         dp.EXINT.eimsk.modify(|_, w| w.int0().set_bit());
    |                                        ^^^^ help: there is a method with a similar name: `int`

error[E0599]: no method named `int1` found for mutable reference `&mut arduino_hal::pac::exint::eimsk::W` in the current scope
   --> src/main.rs:151:34
    |
151 |         dp.EXINT.eimsk.modify(|_, w| w.int1().set_bit());
    |                                        ^^^^ help: there is a method with a similar name: `int`

I don't see any difference regarding EIMSK or INT0 between the 328's and 2560's atdf files so I don't understand.
It compiles when the eimsk lines are commented.

According to Arduino documentation, Uno and Mega2560 use the same pins for INT0 and INT1. Except this:

Note that in the table below, the interrupt numbers refer to the number to be passed to attachInterrupt(). For historical reasons, this numbering does not always correspond directly to the interrupt numbering on the ATmega chip (e.g. int.0 corresponds to INT4 on the ATmega2560 chip).

System info

ArchLinux. uname -a -> Linux 5.15.87-1-lts #1 SMP Thu, 12 Jan 2023 15:51:39 +0000 x86_64 GNU/Linux
channel = "nightly-2022-10-22"

arduino-hal v0.1.0 (https://github.com/Rahix/avr-hal#4c9c44c3)
│   ├── atmega-hal v0.1.0 (https://github.com/Rahix/avr-hal#4c9c44c3)
│   │   ├── avr-device v0.5.0

Using the provided JSON AVR specs.

@ZettaScript
Copy link
Author

ZettaScript commented Jan 18, 2023

Looking at the code, datasheet and attachInterrupt, I found this works:

dp.EXINT.eicrb.modify(|_, w| w.isc4().bits(INT_CHANGE));
dp.EXINT.eicrb.modify(|_, w| w.isc5().bits(INT_CHANGE));
dp.EXINT.eimsk.modify(|_, w| w.int().bits(1<<4 | 1<<5));

And I also renamed the functions INT0,INT1 into INT4,INT5.

@Tellurian-Ul
Copy link

Just want to post that I'm having the same problem. I'm surprised you closed this issue.

@Rahix
Copy link
Owner

Rahix commented Mar 5, 2024

@Tellurian-Ul can you elaborate on the issue a bit? Is the problem that the generated field accessors in avr-device don't match register descriptions from the datasheet?

@Rahix
Copy link
Owner

Rahix commented Mar 5, 2024

And for reference, it seems we are patching EIMSK for ATmega328P:

https://github.com/Rahix/avr-device/blob/1b0b406b376d0d12eb4ac189b011458a7c906ed7/patch/atmega328p.yaml#L13C1-L18C18

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

3 participants